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

面向接口编程,把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 {

你可能感兴趣的:(工具,spring-boot)