Dubbo 以Zookeeper为注册中心整合 SpringMVC 遇到的问题
问题一:
问题描述:
暂时做的是双服务即Provider与Consumer分离,所以各自启动服务,项目配置完成后成功启动但是没有在
ZookeeperClient中看到暴露的服务接口,使用JMeter获取服务列表也是一样;
解决方法:
原配置为:
<!-- 扫描声明需要暴露的服务接口 -->
<dubbo:annotation/>
修改后的配置为:
<!-- 扫描声明需要暴露的服务接口 -->
<dubbo:annotation package="com.ccit.dubbo.api.service"/>
当前为注解方式使用Dubbo的@service注解,需要在标签中指定扫描范围以找到接口包完成注册
问题二 :
问题描述:
Consumer服务配置完成后启动报错报错信息大致意思为未能在提供者找到对应接口
(如:com.ccit.dubbo.api.service.DemoService)的服务;
解决方法:
使用@Reference注解时,给注解加上属性(Version="X.X.X"),
Zookeeper指定服务接口需要的属性包含Version,group等
问题三:
问题描述:
使用@Reference注解获取的Bean实例为null;
解决方法:
原先的配置为将applicationConsumer.xml配置Import到applicationContext中,
经查阅资料将该配置文件引入到了springMVC的配置文件中,原因为在web.xml中配置了ContextLoaderListener并且
配置文件为applicationContet.xml所以在此时@Reference注解被扫描时,springmvc还未开始加载,
ContextLoaderListener加载是在springmvc配置加载之前
问题四:
问题描述:
使用网页访问Consumer或者使用JMeter测试Zookeeper接口跟Consumer接口时返回值包含中文乱码;
解决办法:
在Consumer方返回的中文乱码是因为在web.xml配置时忘记在CharacterEncodingFilter配置中添加forceEncoding,
导致返回值为乱码:
修改配置前的配置为:
<!-- 字符集监控 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
修改后的配置为:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
问题五:
问题描述:
在问题四处理完成后,使用JMeter调用Zookeeper接口仍然返回中文乱码,刚开始是认为Zookeeper的返回问题,后来
经DebugConsumer放的返回值返现依然是中文,那么猜测是JMeter的问题
解决方法:
修改JMeter安装目录下bin目录下的jmeter.properties配置文件,将文件中的大概1084行的
#sampleresult.default.encoding=ISO-8859-1
注释放开并将默认的ISO-8859-1改为UTF-8,例如:
sampleresult.default.encoding=UTF-8
再次测试后问题解决;