Error starting ApplicationContext.Caused by: org.springframework.beans.factory.BeanCreationException

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中的依赖去掉,这样就能正常启动项目了。**

在这里插入图片描述
最后正常的运行结果:
在这里插入图片描述
参考的博文是:此文中的评论更有惊喜!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值