Failed to load ApplicationContext

这篇博客讨论了在Spring应用中遇到的ApplicationContext加载失败问题,具体表现为UnsatisfiedDependencyException,原因是缺少对EmployeeService的bean定义。错误在单元测试运行时暴露,解决方案是在对应的service实现类上添加@Service注解。

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

警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘employeeController’: Unsatisfied dependency expressed through field ‘employeeService’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.cdhg.service.EmployeeService’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 七月 26, 2020 1:13:54 上午 com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl info 信息: {dataSource-1} closed 七月 26, 2020 1:13:54 上午 org.springframework.test.context.TestContextManager prepareTestInstance 严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@6e06451e] to prepare test instance [com.cdhg.test.MVCTest@72c28d64] java.lang.IllegalStateException: Failed to load ApplicationContext 单元测试出现的问题

1、在出现了以下的错误信息的时候

警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeController': Unsatisfied dependency expressed through field 'employeeService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.cdhg.service.EmployeeService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
七月 26, 2020 1:13:54 上午 com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl info
信息: {dataSource-1} closed
七月 26, 2020 1:13:54 上午 org.springframework.test.context.TestContextManager prepareTestInstance
严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@6e06451e] to prepare test instance [com.cdhg.test.MVCTest@72c28d64]
java.lang.IllegalStateException: Failed to load ApplicationContext

是你在service层实现接口service类处未添加@service,导致@Autowired注入失败

@Service
public class EmployeeServiceImpl implements EmployeeService {
	@Autowired
	EmployeeMapper employeeMapper;

在实现类上添加@Service问题解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值