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<User> getAll() {
        List<User> users = userMapper.selectAll();
        System.out.println(users);
        return users;
    }
}
  <!--声明需要暴露的服务接口 -->
    <dubbo:service interface="com.user.service.UserService"
                  ref="userService" protocol="dubbo" timeout="5000"/>

    <dubbo:protocol name="dubbo" port="20000" ></dubbo:protocol>
    <dubbo:application name="user-server"/>
    <dubbo:registry address="zookeeper://192.168.56.128:2181"/>
    <dubbo:annotation package="com.user.service.impl" />


启动就报错

 

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<User> getAll() {
        List<User> users = userMapper.selectAll();
        System.out.println(users);
        return users;
    }
}

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

 

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值