导入下载的springboot项目竟然报错:org.springframework.beans.factory.BeanCreationException

目录

1.背景

2.解决方法


 

1.背景

今天在spring官网上面下载了一个springboot项目下来,想要学习一下,导入自己的idea并且把Tomcat端口号配置好,redis也设置好了,数据库也创建了,并且把相应的sql文件已经导入了数据库,并且生成了相应的表和数据。当我启动springboot项目的时候就报了下面的错:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-06-02 20:36:40.115 ERROR 19136 --- [           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: Found non-empty schema(s) `vhr` without schema history table! Use baseline() or set baselineOnMigrate to true to initialize the schema history table.
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:307) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.javaboy.vhr.VhrApplication.main(VhrApplication.java:16) [classes/:na]
Caused by: org.flywaydb.core.api.FlywayException: Found non-empty schema(s) `vhr` without schema history table! Use baseline() or set baselineOnMigrate to true to initialize the schema history table.
	at org.flywaydb.core.Flyway$1.execute(Flyway.java:1386) ~[flyway-core-5.2.4.jar:na]
	at org.flywaydb.core.Flyway$1.execute(Flyway.java:1356) ~[flyway-core-5.2.4.jar:na]
	at org.flywaydb.core.Flyway.execute(Flyway.java:1711) ~[flyway-core-5.2.4.jar:na]
	at org.flywaydb.core.Flyway.migrate(Flyway.java:1356) ~[flyway-core-5.2.4.jar:na]
	at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65) ~[spring-boot-autoconfigure-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	... 18 common frames omitted

2.解决方法

我上网找了好多方法都没有用,例如是否属性注入出现了问题、@Service是否都写了等,后来我自己查看mapper层的pom.xml文件,发现里面引入了以下的依赖:

<dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
</dependency>

和这句报错的有点相似,里面有个'flywayInitializer',

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource 

后来我百度了一下,flywaydb会帮我们创建表和表的数据,解决了以前只能靠发布者手动执行的问题,因为我是先创建数据库再导入表的,所以报错了,于是我新建了一个数据库,但是我没有自己手动导入sql文件,然后运行springboot项目,问题就解决了!希望能够帮到大家!

 

 各位可以关注下面这个公众号,这个公众号会分享一些相关的技术型的文章或者开发遇到的常见问题。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!关于您使用MongoTemplate启动时报错的问题,我可以提供一些常见的解决方案给您参考。首先,BeanCreationException通常是由于Spring容器在创建bean时遇到了问题而引发的异常。以下是一些可能的原因和解决方法: 1. 检查依赖是否正确配置:请确保您的项目中已经正确地配置了MongoDB的依赖项。您可以使用Maven或Gradle等构建工具来管理依赖关系,并确保版本与您的Spring版本兼容。 2. 确认MongoDB服务器是否正常运行:请确保MongoDB服务器已经正确地启动并正在运行。您可以尝试使用mongo命令行工具连接到MongoDB服务器,以验证服务器是否正常工作。 3. 检查MongoDB连接配置:请确保您在应用程序的配置文件中正确配置了MongoDB的连接参数,包括主机、端口、数据库名称和身份验证信息(如果适用)。您可以检查这些配置是否与MongoDB服务器的配置相匹配。 4. 检查bean名称和注解:如果您在配置文件中手动配置了MongoTemplate bean,请确保bean的名称与注入它的地方匹配。另外,请确保在类或方法上正确使用了相关的注解,例如@Configuration和@Bean。 5. 检查类路径扫描:如果使用了基于注解的配置方式,请确保Spring能够扫描到MongoTemplate所在的包。您可以检查@ComponentScan注解或在配置类上使用@ComponentScan来确保正确的扫描路径。 如果您提供更多的错误信息或相关的代码片段,我可以为您提供更具体的帮助。希望以上信息对您有所帮助!如有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值