gpt4 book ai didi

liquibase - jhipster 使用 prod 配置文件运行嵌入式 jar - liquibase 问题

转载 作者:行者123 更新时间:2023-12-01 15:00:35 25 4
gpt4 key购买 nike

我已将我的应用程序打包为:mvn -Pprod 包

然后我跑了

java -jar myapp-0.0.1-SNAPSHOT.war

它工作正常。但是如果我运行:

java -jar myapp-0.0.1-SNAPSHOT.war --spring.profiles.active=prod

我收到这个错误:

[ERROR] org.springframework.boot.context.embedded.tomcat.ServletContextInitializerLifecycleListener - Error starting Tomcat context: org.springframework.beans.factory.BeanCreationException
[WARN] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:124) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) ~[spring-context-4.1.3.RELEASE.jar!/:4.1.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at com.myapp.Application.main(Application.java:57) [classes!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53) [bioandbio-0.0.1-SNAPSHOT.war:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25]
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:97) ~[spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:74) ~[spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:374) ~[spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:150) ~[spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:148) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:121) [spring-boot-1.2.0.RELEASE.jar!/:1.2.0.RELEASE]
... 11 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService com.myapp.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.myapp.repository.UserRepository com.myapp.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#1f1288f5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1f1288f5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [com/myapp/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ValidationFailedException: Validation Failed:
1 change sets check sum
classpath:config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster is now: 7:788e6cd59e4764c45e1b83437356e748

我不明白为什么产品配置文件会导致此问题。如果有人知道这里出了什么问题

谢谢。

最佳答案

一直阅读到堆栈跟踪的底部,我发现根本原因是 liquibase 校验和验证失败。我不确定您对 liquibase 有多熟悉,但它是一个嵌入在 jhipster 中的工具,用于在对象更改时管理数据库架构更改。 liquibase 所做的是使用 XML 格式将数据库模式描述为一系列“变更集”。当 liquibase 部署一个变更集时(即一个变更集说'id为“CreateTableFoo”的变更集是“用列bar baz等创建表foo”)是它实际上创建了表,然后它还向名为'的表添加了一行databasechangelog'记录了变更集“CreateTableFoo”在某某时间被成功应用,并且该变更集的校验和是某个值。现在,如果您来更改变更集 xml 文件,以便变更集“CreateTableFoo”创建一个具有不同名称或不同列的表,那么为该变更集计算的校验和也会更改,因此当您尝试更新架构 liquibase说“等等!出了点问题!”

这就是这里发生的事情。

创建类路径资源 [com/myapp/config/DatabaseConfiguration.class] 中定义的名称为“liquibase”的 bean 时出错:调用 init 方法失败;嵌套异常是 liquibase.exception.ValidationFailedException:验证失败:
1 更改集校验和
classpath:config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster 现在是:7:788e6cd59e4764c45e1b83437356e748

这表明 prod 数据库已经在其上运行了 liquibase 更新以填充架构,但变更集自初始部署以来已更改。我不熟悉 jhipster 如何使用 liquibase,因此您需要查看文件 classpath:config/liquibase/changelog/00000000000000_initial_schema.xml 以查看它尝试设置的数据库架构,以及将其与生产中实际存在的模式进行比较。

现在事情不同步了,你必须想办法让它们恢复同步,这比这里能回答的更复杂,很大程度上取决于变更日志和生产模式之间的差异是。

关于liquibase - jhipster 使用 prod 配置文件运行嵌入式 jar - liquibase 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28427950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com