Error Creating bean with name flywayInitializer defined in class path Resource

Asked

Viewed 3,952 times

-2

I am trying to add new fields to my table in my Spring Boot project using Flyway, and I am not getting this error message.

2020-04-29 12:53:36.345  WARN 544 --- [  restartedMain]
ConfigServletWebServerApplicationContext : Exception encountered
during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'flywayInitializer' defined in class path
resource
[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
Invocation of init method failed; nested exception is
org.flywaydb.core.api.FlywayException: Validate failed:  Migration
checksum mismatch for migration version 02
-> Applied to database : 0
-> Resolved locally    : -1105036925

2020-04-29 12:53:36.346  INFO 544 --- [  restartedMain]
com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown
initiated... 2020-04-29 12:53:36.347  INFO 544 --- [  restartedMain]
com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown
completed. 2020-04-29 12:53:36.350  INFO 544 --- [  restartedMain]
o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-04-29 12:53:36.359  INFO 544 --- [  restartedMain]
ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report
re-run your application with 'debug' enabled. 2020-04-29 12:53:36.366
ERROR 544 --- [  restartedMain] o.s.boot.SpringApplication            
: Application run failed

org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'flywayInitializer' defined in class path
resource
[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
Invocation of init method failed; nested exception is
org.flywaydb.core.api.FlywayException: Validate failed:  Migration
checksum mismatch for migration version 02
-> Applied to database : 0
-> Resolved locally    : -1105036925

    at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]     at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]     at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]     at
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]     at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]     at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]     at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]     at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]     at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]     at
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108)
~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]   at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]   at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]   at
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]  at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]   at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]   at
org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]   at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]   at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]   at
com.server.agenda.AgendaApplication.main(AgendaApplication.java:10)
[classes/:na]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method) ~[na:1.8.0_241]     at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
~[na:1.8.0_241]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
~[na:1.8.0_241]     at java.lang.reflect.Method.invoke(Unknown Source)
~[na:1.8.0_241]     at
org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
[spring-boot-devtools-2.2.6.RELEASE.jar:2.2.6.RELEASE] Caused by:
org.flywaydb.core.api.FlywayException: Validate failed:  Migration
checksum mismatch for migration version 02
-> Applied to database : 0
-> Resolved locally    : -1105036925

    at org.flywaydb.core.Flyway.doValidate(Flyway.java:275)
~[flyway-core-6.0.8.jar:na]     at
org.flywaydb.core.Flyway.access$100(Flyway.java:79)
~[flyway-core-6.0.8.jar:na]     at
org.flywaydb.core.Flyway$1.execute(Flyway.java:157)
~[flyway-core-6.0.8.jar:na]     at
org.flywaydb.core.Flyway$1.execute(Flyway.java:149)
~[flyway-core-6.0.8.jar:na]     at
org.flywaydb.core.Flyway.execute(Flyway.java:511)
~[flyway-core-6.0.8.jar:na]     at
org.flywaydb.core.Flyway.migrate(Flyway.java:149)
~[flyway-core-6.0.8.jar:na]     at
org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65)
~[spring-boot-autoconfigure-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]     at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]     ... 23 common frames
omitted

The project structure is correct, the files are named correct, the sql script is also right, do not know where the problem is, note.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

My database is the Postgre

2 answers

1


I will answer this question based on the title you have placed and based on the fact that you are trying to add new fields to the table:

If you are always changing the same script after you have already run the project and created the tables and the flyway_schema_history, you need:

  • or delete all tables and run again
  • or you delete the table data flyway_schema_history.

-2

Each time you run a run in the application and your version of flyway has been modified, a new version is generated in flyway_schema_history in your database, when you change a version that has already run in your application and try to run it again, it returns error because that version already exists, so whenever you change, I advise you to create a new version and then put the application to run the most indicated if you did that is go in the database and delete all tables and run again for the error to stop happening.

  • When asking a question, always ask the whole question. Replying to your follow-up complicates the visualization of anyone who can help you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.