创建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,谢谢