欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

遇到Error creating bean with name 'flywayInitializer' defined in class path resource解决办法

程序员文章站 2022-05-19 10:02:05
...

很多小伙伴在启动项目的时候报了这个错误

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-27 10:46:35.531 ERROR 17208 [main] 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 9
-> Applied to database : -450216138
-> Resolved locally    : -450216137
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
	at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$139/88397182.getObject(Unknown Source)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:307)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
	at com.yocoyt.dcams.DcamsApplication.main(DcamsApplication.java:24)
Caused by: org.flywaydb.core.api.FlywayException: Validate failed: Migration checksum mismatch for migration version 9
-> Applied to database : -450216138
-> Resolved locally    : -450216137
	at org.flywaydb.core.Flyway.doValidate(Flyway.java:1482)
	at org.flywaydb.core.Flyway.access$100(Flyway.java:85)
	at org.flywaydb.core.Flyway$1.execute(Flyway.java:1364)
	at org.flywaydb.core.Flyway$1.execute(Flyway.java:1356)
	at org.flywaydb.core.Flyway.execute(Flyway.java:1711)
	at org.flywaydb.core.Flyway.migrate(Flyway.java:1356)
	at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)
	... 19 common frames omitted

这是因为项目脚本被修改了,版本号已经更新了,而你的版本号还在落后于当前版本,所以启动项目就报错了,解决办法是这样的:
遇到Error creating bean with name 'flywayInitializer' defined in class path resource解决办法
将这个Resolved locally后面的版本号复制下来,连着符号一起复制,然后找到你数据库中的flyway_change_log这个表,在最下面那一行数据中把刚刚复制的版本号替换进去就可以了
遇到Error creating bean with name 'flywayInitializer' defined in class path resource解决办法
修改版本号,将刚刚从报错信息里面复制来的版本号复制到这里
遇到Error creating bean with name 'flywayInitializer' defined in class path resource解决办法
然后再启动,完美!
还有第二种方法,适用于自己不懂的时候将数据库给删了的小伙伴
就是桌面右键点击Git Bash here,然后移除你的数据库。再去你的项目中运行你启动项目的那个命令然后生成数据库之后再去启动项目即可!
遇到Error creating bean with name 'flywayInitializer' defined in class path resource解决办法