org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userController’
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userController’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.cyj.service.UserService com.cyj.web.controller.UserController.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userService’: FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.cyj.service.UserService. No provider available for the service com.cyj.service.UserService from the url zookeeper://192.168.41.144:2181/com.alibaba.dubbo.registry.RegistryService?application=myconsumer&dubbo=2.5.4&interface=com.cyj.service.UserService&methods=userLogin&pid=30860&revision=1.0-SNAPSHOT&side=consumer×tamp=1571022093812 to the consumer 192.168.245.1 use dubbo version 2.5.4
在服务Provider启动成功,且服务也发布成功情况下。访问消费者进入了登陆界面点击需要控制层操作时出现如上错误。
解决:
数据库问题,我的idea里面连接数据库写的是
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.41.144:3306/maven?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
因为本地数据库名字为localhost;
且因为该项目用到了dubbo,开启了集群,当初装liunx的时候安装的mysql是开机自动启动的,所以代码里写了虚拟机的IP,所以就连接上了虚拟机的而不是本地的。最重要的是虚拟机里的mysql没有maven我要链接的这个数据库。改成
jdbc.url=jdbc:mysql://localhost:3306/maven?characterEncoding=utf-8
就可以了。