警告: 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问题解决