jhipster运行带有prod配置文件的嵌入式jar-liquibase的问题 [英] jhipster run embedded jar with prod profile - issue with liquibase

查看:64
本文介绍了jhipster运行带有prod配置文件的嵌入式jar-liquibase的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将我的应用打包为: 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"的变更集是使用列栏baz等创建表foo"),它实际上是在创建该表,然后还在名为'的表中添加一行记录更改集"CreateTableFoo"在某个时间成功应用的"databasechangelog",并且该更改集的校验和具有一定的价值.现在,如果您来更改更改集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

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

现在一切都不同步了,您必须找出一种使它们恢复同步的方法,这种方法比这里可以回答的要复杂得多,并且在很大程度上取决于变更日志和生产模式之间的差异是.

I have packaged my app with : mvn -Pprod package

Then I ran

java -jar myapp-0.0.1-SNAPSHOT.war

it works fine. But if I run :

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

I am getting this error:

[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

I don't understand why prod profile causes this issue. If someone knows what's wrong here

Thank you.

解决方案

Reading all the way to the bottom of the stack trace, I see that the root cause is a liquibase checksum validation failure. I'm not sure how familiar you are with liquibase, but it is a tool that is embedded inside jhipster that is used to manage database schema changes as your objects change. What liquibase does is use an XML format to describe the database schema as a series of 'changesets'. When liquibase deploys a changeset (i.e. a changeset that says 'changeset with id "CreateTableFoo" is "create table foo with columns bar baz etc") is that it actually creates the table, and then it also adds a row to a table called 'databasechangelog' that records that the changeset "CreateTableFoo" was successfully applied at such and such a time, and the checksum of that changeset was some value. Now, if you come along and change the changeset xml file so that the changeset "CreateTableFoo" instead creates a table with a different name or different columns, then the checksum calculated for that changeset also changes, so when you try to update the schema liquibase says "Wait! Something wrong!"

So that is what is happening here.

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

What this indicates is that the prod database already has had a liquibase update run on it to populate the schema, but that the changeset has changed since that initial deploy. I am not familiar with how jhipster uses liquibase, so you would need to look at the file classpath:config/liquibase/changelog/00000000000000_initial_schema.xml to see what database schema it is trying to set up, and compare that to the schema that is actually in place in production.

Now that things are out of sync, you'll have to figure out a way to get them back in sync, which is more complicated than can be answered here and depends greatly on what the differences between the changelog and the production schema are.

这篇关于jhipster运行带有prod配置文件的嵌入式jar-liquibase的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆