dubbo注入失败原因分析解决

您所在的位置:网站首页 接口注入失败 dubbo注入失败原因分析解决

dubbo注入失败原因分析解决

2024-07-12 14:57| 来源: 网络整理| 查看: 265

INFO 14280 — [nio-8001-exec-1] trationDelegate$BeanPostProcessorChecker : Bean ‘error’ of type [org.springframework.web.servlet.view.InternalResourceView] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 报错原因: 1、 在pom.xml里面需要加log4j的配置。

log4j log4j 1.2.7

2、 看包路径是否与文件路径一致 在这里插入图片描述

## StringBoot 集成 Dubbo 相关配置信息:服务端配置示例 #注册服务名称 spring.dubbo.application.name=provider #zookeeper 注册中心地址 spring.dubbo.registry.address=zookeeper://127.0.0.1:2181 #服务端提供端使用协议 spring.dubbo.protocol.name=dubbo #服务端提供端暴露端口号 spring.dubbo.protocol.port=20882 #服务所在包名称 spring.dubbo.scan=com.lj.dubbo #应用端口 server.port=8002 #应用项目名称 server.servlet.context-path=/ #修改 tomcat 的 URIEncoding 为 UTF-8 server.tomcat.uri-encoding=UTF-8 #jackson 对日期时间格式化设置:时间格式 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss #jackson 对日期时间格式化设置:时区设置 spring.jackson.time-zone=GMT+8

3、 按顺序启动服务 先启动服务提供者 provider,在服务消费者 consumer在这里插入图片描述 4、 服务提供者provider里面的@service要用alibaba的包在这里插入图片描述

package com.lj.dubbo.service.impl; import org.springframework.beans.factory.annotation.Value; import com.alibaba.dubbo.config.annotation.Service; import com.lj.service.UserService; @Service public class UserServiceImpl implements UserService { @Value("${server.port}") private String port; @Override public String getUserId(Integer id) { System.out.println("springboot-dubbo-provider"+port+"被消费的id:"+id); if (id==1) { return "王者"+port; }else if (id==2) { return "吃鸡"+port; }else { return "随缘"+port; } } }

5、 服务消费者comsumer里面需要用dubbo的@Reference远程注解注入而不是spring的注解注入 @Reference支持远程注入 @Autowired@Resource只支持本地注入在这里插入图片描述

package com.lj.service.impl; import com.lj.UserService; import org.springframework.stereotype.Component; import com.alibaba.dubbo.config.annotation.Reference; //使用@Component 或者 @Service 或者其他的spring 组件扫描注解都可以 @Component public class UserServiceConsumer{ @Reference //dubbo直连 private UserService userService; public String getUserId(Integer id) { return userService.getUserId(id); } }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3