Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
*1.在学习SpringBoot2.x的时候,搭建了demo-project项目,学完SpringBoot后,然后就开始写另一个项目,但后来又重新想启动demo-project项目的时候这时候就出现大问题了,结果展示如下*
**报的异常是:**错误的创建了一个bean名字,初始bean失败
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-01-21 13:54:59.658 ERROR 11988 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
2021-01-21 13:54:59.674 WARN 11988 --- [ restartedMain] o.s.boot.SpringApplication : Unable to close ApplicationContext
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.devtools.autoconfigure.LocalDevToolsAutoConfiguration$LiveReloadConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:603) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~
~~~~~~~~~~~~~
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available
经过一番不断的浏览别人的博文,知道了如何解决问题,但是原理还不太了解,所以也只能模糊更改,后期学习在完善!
说明:在这个项目里没有链接数据库,用的是集合里存储数据进行模拟,但是在后期会用到数据库,所以我就提前把maven所需要的依赖都加到了pom.xml文件中,就是因为这个原因才导致的上面的报错的。
**方法有两种:**
1. 可以在你的启动类代码中,@SpringBootApplication()注解改动一下:()里面加上**exclude = DataSourceAutoConfiguration.class**
//项目启动类的注解
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
//使用Servlet3.0的注解进行开发自定义的过滤器
@ServletComponentScan
//@EnableScheduling开启定时任务,自动扫描
@EnableScheduling
//开启异步任务的注解
@EnableAsync
public class DemoProjectApplication {
public static void main(String[] args) {
SpringApplication.run(DemoProjectApplication.class,args);
}
}
**2.也可以pom.xml中的依赖去掉,这样就能正常启动项目了。**
最后正常的运行结果:
参考的博文是:此文中的评论更有惊喜!