xiaolenglala
xiaolenglala
采纳率50%
2019-12-21 22:41 阅读 882

dubbo消费方调用不到服务方问题

消费方 配置 和代码:
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance " xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

    <servlet>   <!-- 配置servlet -->
        <servlet-name>HelloWeb</servlet-name>    <!-- 可以理解为刚给当前servlet起名字,可自定义 -->
        <!-- springmvc的核心处理器,不可自定义 -->
        <servlet-class>
           org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <!-- 配置Spring mvc下的配置文件的位置和名称 -->
        <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>
    <!-- 可以理解为指定被Mapping的servlet的名称(代码第二行中的名称相同) -->
    <servlet-name>HelloWeb</servlet-name>
        <!-- 配置拦截路径,/表示全拦截 -->
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>

</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dubbo = "http://code.alibabatech.com/schema/dubbo"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://code.alibabatech.com/schema/dubbo
    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
   <context:annotation-config/>
   <!-- bean definitions go here--> 
   <!-- 配置dubbo的应用名称 -->
   <dubbo:application name="student_consumer"></dubbo:application>
   <!-- 配置dubbo的配置中心 
   <dubbo:registry  protocol="zookeeper" address="zookeeper://122.51.144.197:2181" ></dubbo:registry>-->
   <dubbo:registry protocol="zookeeper" address="zookeeper://192.168.234.118:2181" ></dubbo:registry>
   <!-- 配置dubbo的扫描包 将@service注解的类放入dubbo扫描包,供dubbo远程调用(RPC)时使用-->
   <dubbo:annotation package="org.controller"></dubbo:annotation>
    <!-- 注入到spring的 ioc容器中 -->
    <context:component-scan base-package="org.controller"></context:component-scan> 

----------------------------------------------------代码
图片说明

提供方
配置
图片说明

代码:

package com.test.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.test.api.StudentServer;

@Service //alibaba
public class StudentServerImpl implements StudentServer{

    public String server(String name) {
        String hello="你好,很高心遇见你!";
        return hello;
    }

}

报错信息:
Servlet.service() for servlet [HelloWeb] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at org.controller.StudentController.rpcServer(StudentController.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • weixin_43466240 weixin_43466240 2019-12-22 10:44

    加上版本号试试
    @org.apache.dubbo.config.annotation.Service(validation = "true", version = "1.0.0")
    provider

    @Reference(validation = "true", version = "1.0.0")
    consumer

    点赞 评论 复制链接分享

相关推荐