Dubbo+Zookeeper后台项目中服务注册不上

1、接口调用时页面报404,后台发现不了请求的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、服务启动后一直没有收到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、扫描不到服务
2、地址拦截,请求不通过
3、因为使用了dubbo,在导包注解可能存在导错其他包


排查:

1、翻看多次配置,发现能正常扫描到指定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注解驱动-->
    <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>
    <!--应用名称-->
    <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();
    }
}

以上问题解决方法都试过后,发现不符合本次问题解决方式。项目之前有过做过,经过多次对比也没有发现有什么不同之处,最后找朋友看了下,才发现问题

本次问题的原因:

在建立模块时选择了web项目
在这里插入图片描述
main下面自动生成的文件夹名为data,导致服务找不到
在这里插入图片描述

本次问题的解决方法:

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

接口调用正常:

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
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐