Consider defining a bean of type 'com.xxx.service.impl.xxxImpl' in your configuration

xiaoxiao2021-02-28  31

面向接口编程,把Service层定义为接口,然后用另外一个类去实现这个接口,使用spring boot启动时报错

项目结构:

controller层注入如下

@Autowired private UserServiceImpl userService;

错误详情

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2017-09-30 10:06:33.611 ERROR 7736 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Field userService in com.adtec.vuespringboot.controller.UserController required a bean of type 'com.adtec.vuespringboot.service.impl.UserServiceImpl' that could not be found. Action: Consider defining a bean of type 'com.adtec.vuespringboot.service.impl.UserServiceImpl' in your configuration.

这可能是因为spring boot默认找的是service层的类,而Service里面并没有UserServiceImpl这个类

解决方案:

在UserServiceImpl类上添加注解@Service

@Service public class UserServiceImpl implements UserService {
转载请注明原文地址: https://www.6miu.com/read-600199.html

最新回复(0)