dubbo服務(wù)無法注冊到zookeeper的問題
Dubbo+Zookeeper后臺項目中服務(wù)注冊不上
1、接口調(diào)用時頁面報404,后臺發(fā)現(xiàn)不了請求的url
19:51:56,458 DEBUG DispatcherServlet:891 - DispatcherServlet with name 'springmvc' processing GET request for [/custmer/findAll.do] 19:51:56,460 DEBUG RequestMappingHandlerMapping:312 - Looking up handler method for path /custmer/findAll.do 19:51:56,461 DEBUG RequestMappingHandlerMapping:322 - Did not find handler method for [/custmer/findAll.do] 19:51:56,462 WARN PageNotFound:1205 - No mapping found for HTTP request with URI [/custmer/findAll.do] in DispatcherServlet with name 'springmvc' 19:51:56,462 DEBUG DispatcherServlet:1000 - Successfully completed request
2、服務(wù)啟動后一直沒有收到zookeeper心跳機制的反饋,正常情況下日志中會打印出來
19:51:20,214 INFO DispatcherServlet:509 - FrameworkServlet 'springmvc': initialization completed in 1771 ms 19:51:20,214 DEBUG DispatcherServlet:175 - Servlet 'springmvc' configured successfully 五月 03, 2022 7:51:20 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-bio-82"]
可能存在的問題
1、掃描不到服務(wù)
2、地址攔截,請求不通過
3、因為使用了dubbo,在導包注解可能存在導錯其他包
排查
1、翻看多次配置,發(fā)現(xiàn)能正常掃描到指定controller文件
<web-app>
<!--提供外部接口訪問-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring-mvc.xml</param-value>
</init-param>
<!--初始化容器-->
<load-on-startup>1</load-on-startup>
</servlet>
<!--匹配-->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
<beans>
<!--mvc注解驅(qū)動-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--dubbo包掃描-->
<dubbo:annotation package="com.happy.web"></dubbo:annotation>
<!--注冊中心-->
<dubbo:registry address="zookeeper://127.0.0.1:2181"></dubbo:registry>
<!--應(yīng)用名稱-->
<dubbo:application name="happy-web"></dubbo:application>
<!--消費端啟動檢查-->
<dubbo:consumer check="false" timeout="6000000"></dubbo:consumer>
</beans>
2、tomcat中配置了任何請求都可以到達
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<!--指定端口-->
<port>82</port>
<!--請求路徑-->
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
3、controller和service中導入的包正常
import com.alibaba.dubbo.config.annotation.Reference;
import com.happy.pojo.Custmer;
import com.happy.service.CustmerService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/custmer")
public class CustmerController {
@Reference
CustmerService custmerService;
@RequestMapping("/findAll")
public List<Custmer> findAll() {
List<Custmer> all = custmerService.findAll();
return all;
}
}
import com.alibaba.dubbo.config.annotation.Service;
import com.happy.dao.CustmerMapper;
import com.happy.pojo.Custmer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
@Service(interfaceClass = CustmerService.class)
@Transactional
public class CustmerServiceImpl implements CustmerService {
@Autowired
CustmerMapper custmerMapper;
@Override
public List<Custmer> findAll() {
return custmerMapper.findAll();
}
}
以上問題解決方法都試過后,發(fā)現(xiàn)不符合本次問題解決方式。項目之前有過做過,經(jīng)過多次對比也沒有發(fā)現(xiàn)有什么不同之處,最后找朋友看了下,才發(fā)現(xiàn)問題
本次問題的原因
- 在建立模塊時選擇了web項目

- main下面自動生成的文件夾名為data,導致服務(wù)找不到

本次問題的解決方法
main下面的文件名更改為java后正常

zookeeper心跳機制正常:
20:32:51,927 INFO DispatcherServlet:509 - FrameworkServlet 'springmvc': initialization completed in 3575 ms 20:32:51,927 DEBUG DispatcherServlet:175 - Servlet 'springmvc' configured successfully 五月 03, 2022 8:32:51 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-bio-82"] 20:32:56,208 DEBUG ClientCnxn:766 - Got notification sessionid:0x18089b835320006
接口調(diào)用正常:
20:33:29,254 DEBUG DispatcherServlet:891 - DispatcherServlet with name 'springmvc' processing GET request for [/custmer/findAll.do] 20:33:29,255 DEBUG RequestMappingHandlerMapping:312 - Looking up handler method for path /custmer/findAll.do 20:33:29,259 DEBUG RequestMappingHandlerMapping:319 - Returning handler method [public java.util.List<com.happy.pojo.Custmer> com.happy.web.CustmerController.findAll()] 20:33:29,259 DEBUG DefaultListableBeanFactory:254 - Returning cached instance of singleton bean 'custmerController' 20:33:29,260 DEBUG DispatcherServlet:979 - Last-Modified value for [/custmer/findAll.do] is: -1 20:33:34,892 DEBUG DecodeHandler:58 - [DUBBO] Decode decodeable message com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcResult, dubbo version: 2.6.0, current host: 192.168.1.115 20:33:34,967 DEBUG RequestResponseBodyMethodProcessor:277 - Written [[Custmer(id=1, name=小王), Custmer(id=2, name=小楊), Custmer(id=3, name=小劉), Custmer(id=4, name=小李)]] as "application/json" using [org.springframework.http.converter.json.GsonHttpMessageConverter@3b3104b1] 20:33:34,969 DEBUG DispatcherServlet:1076 - Null ModelAndView returned to DispatcherServlet with name 'springmvc': assuming HandlerAdapter completed request handling 20:33:34,971 DEBUG DispatcherServlet:1000 - Successfully completed request
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java后端產(chǎn)生驗證碼后臺驗證功能的實現(xiàn)代碼
這篇文章主要介紹了Java后臺產(chǎn)生驗證碼后臺驗證功能,本文文字結(jié)合實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-06-06
Java實現(xiàn)http請求文件流對帶寬限速獲取md5值
文章介紹了如何在進行HTTP請求下載大數(shù)據(jù)時處理帶寬限制和并發(fā)問題,通過使用緩沖區(qū)和限速邏輯,可以有效控制下載速度,避免掉包和數(shù)據(jù)丟失,核心公式基于帶寬和已下載字節(jié)數(shù)計算預(yù)期耗時,并通過Thread.sleep()進行動態(tài)休眠補償,感興趣的朋友一起看看吧2025-02-02
SpringBoot實現(xiàn)事務(wù)鉤子函數(shù)的示例
本文主要介紹了SpringBoot實現(xiàn)事務(wù)鉤子函數(shù)的示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2025-08-08
Android Home鍵監(jiān)聽的實現(xiàn)代碼
這篇文章主要介紹了Android Home 鍵監(jiān)聽的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-12-12
MyBatis的@SelectProvider注解構(gòu)建動態(tài)SQL方式
這篇文章主要介紹了MyBatis的@SelectProvider注解構(gòu)建動態(tài)SQL方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-08-08
mybatis generator 配置 反向生成Entity簡單增刪改查(推薦)
這篇文章主要介紹了mybatis generator 配置 反向生成Entity簡單增刪改查(推薦)的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-12-12
Spring+SpringMVC+Hibernate整合實例講解
在本篇文章里小編給大家整理的是關(guān)于Spring+SpringMVC+Hibernate整合實例講解,需要的朋友們可以學習下。2020-03-03

