A component required a bean named 'userService' that could not be found.

创建springboot+dubbo在服务端

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List getAll() {
        List users = userMapper.selectAll();
        System.out.println(users);
        return users;
    }
}
  
    

    
    
    
    


启动就报错

 

2018-06-08 09:53:13.785  INFO 6616 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-06-08 09:53:13.785  INFO 6616 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-06-08 09:53:13.785  INFO 6616 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-06-08 09:53:13.785  INFO 6616 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-06-08 09:53:15.202  WARN 6616 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.user.service.UserService': Cannot resolve reference to bean 'userService' while setting bean property 'ref'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userService' available
2018-06-08 09:53:15.222  WARN 6616 --- [           main] o.s.boot.SpringApplication               : Error handling failed (Error creating bean with name 'com.user.service.UserService': Cannot resolve reference to bean 'userService' while setting bean property 'ref'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userService' available)
2018-06-08 09:53:15.395 ERROR 6616 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 


***************************
APPLICATION FAILED TO START
***************************


Description:


A component required a bean named 'userService' that could not be found.




Action:


Consider defining a bean named 'userService' in your configuration.

配置文件不管怎么改都不行,后来在@service后面添加("userService")后服务正常运行

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List getAll() {
        List users = userMapper.selectAll();
        System.out.println(users);
        return users;
    }
}

如果对你有帮助的话请扣个1,谢谢

 

 

你可能感兴趣的:(A component required a bean named 'userService' that could not be found.)