springboot项目启动报错(关于@Resource)

博客讲述Spring Boot项目启动时,在controller层引入Mapper接口用@Resource报错,用@Autowired能正常使用。解决方法是在报错信息里找到pom对应的配置项并注释掉,之后@Autowired和@Resource都能正常使用,还提到@Autowired编译报错的处理办法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-07-10 13:45:09.842 ERROR 10752 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:526)

The following method did not exist:

    org.springframework.beans.factory.config.AutowireCapableBeanFactory.resolveBeanByName(Ljava/lang/String;Lorg/springframework/beans/factory/config/DependencyDescriptor;)Ljava/lang/Object;

The method's class, org.springframework.beans.factory.config.AutowireCapableBeanFactory, is available from the following locations:

    jar:file:/C:/Users/jason/.m2/repository/org/springframework/spring-beans/5.1.3.RELEASE/spring-beans-5.1.3.RELEASE.jar!/org/springframework/beans/factory/config/AutowireCapableBeanFactory.class

It was loaded from the following location:

    file:/C:/Users/jason/.m2/repository/org/springframework/spring-beans/5.1.3.RELEASE/spring-beans-5.1.3.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.beans.factory.config.AutowireCapableBeanFactory


Process finished with exit code 1

以上是报错信息。

错误描述:在controller层引入Mapper接口用的@Resource在项目启动时报错。
报错信息如上,同样的情况用@Autowired就能正常使用。
百思不得其解研究了好久。。。
解决方法:后来在报错信息里找到了pom里对应的配置项,并且注释掉。
在这里插入图片描述
之后就成功了。
@Autowired和@Resource都能正常使用

关于@Autowired编译报错时,可以忽略,或者在接口上面加上@Component注解,如下:
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值