未写service层注解时产生的异常

时间:2022-11-27 00:45:56

报出的错误信息:

ERROR work.web.context.ContextLoader  - Context initialization failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.itheima.service.OrderService com.itheima.service.impl.OrderServiceImpl.orderService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.itheima.service.OrderService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.itheima.service.OrderService com.itheima.service.impl.OrderServiceImpl.orderService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.itheima.service.OrderService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.itheima.service.OrderService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

产生错误的原因:

没在serviceimpl类文件中写注解:

@Service("workBillService")

@Transactional

解决方法:

加上上面的注解即可。