2015-02-10 191 views
2

我已经打包我的应用程序: MVN -Pprod包jhipster运行与督促轮廓嵌入罐子 - 问题与liquibase

然后我跑

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 

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

谢谢。

回答

9

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

所以这就是发生在这里。

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更新,但因为这最初部署的变更发生了变化。我不熟悉jhipster如何使用liquibase,因此您需要查看文件classpath:config/liquibase/changelog/00000000000000_initial_schema.xml以查看它试图设置的数据库模式,并将其与生产中实际存在的模式进行比较。

现在情况不同步,你必须找出一种方法让它们重新同步,这比这里可以回答的更加复杂,并且很大程度上取决于更新日志和生产之间的差异架构是。

+0

感谢这个非常完整的答案,并花费了时间解释一切。现在我的想法非常清楚。 – user1260928 2015-02-10 15:40:30

+0

如果更改日志文件已被应用到数据库后进行编辑,则会发生这种情况。验证错误检测是因为文件与应用时不同。将更改应用于数据库的正确方法是添加新的更改日志文件。 – 2015-02-12 03:43:13