开发者社区> 问答> 正文

dubbo启动消费者报错?报错

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Invocation of init method failed; nested exception is java.lang.IllegalStateException: com.home.service.UserService
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: com.home.service.UserService
at com.alibaba.dubbo.config.ReferenceConfig.checkAndLoadConfig(ReferenceConfig.java:181)
at com.alibaba.dubbo.config.spring.ReferenceBean.afterPropertiesSet(ReferenceBean.java:168)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 21 more
Caused by: java.lang.ClassNotFoundException: com.home.service.UserService
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at com.alibaba.dubbo.config.ReferenceConfig.checkAndLoadConfig(ReferenceConfig.java:178)
... 24 more

展开
收起
爱吃鱼的程序员 2020-06-09 15:50:26 956 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    ClassNotFoundException?我写了一个测试类,运行没有问题,用web.xml启动就报错 IllegalStateException大多是provider没注册上 @liujl110<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns=" http://www.springframework.org/schema/beans"xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"xmlns:dubbo=" http://code.alibabatech...provider没问题,可以在dubbo管控台查看到服务 java.lang.ClassNotFoundException:com.home.service.UserService生产者的接口没加载回复 @开源中国操盘师:重新install会报错回复 @liujl110:可是错误信息显示没拿到啊,重新install下?我的项目是maven管理的,在pom文件中配置了接口的依赖,接口怎么会没加载,在测试类中getBeans就可以拿到啊! <dubbo:consumercheck="false"/>

    关掉tomcat启动时检查服务,如果能正常启动那就是服务不可用了



    这个是加了的,启动tomcat还是报错你的POM能发出来看看吗,感觉像是Dubbo的XML配置没加载进maven~回复 @liujl110:官方git上的pom文件地址如下:https://github.com/alibaba/dubbo/blob/master/pom.xml回复 @liujl110:官网的POM配置上面在dependecy标签后面有个build标签,感觉是少了这个东西,里面是关于maven工程的一些配置回复 @liujl110:在POM最后一行加上这段试试呢,生产者和消费者的POM都加上看看<build><finalName>生产者/消费者名称</finalName><build>我把所有文件都贴出来了,你帮我看下吧。回复 @liujl110:我最近也在学dubbo,这是我从官方文档看到的,所以感觉是POM里面的配置问题,http://dubbo.io/FAQ-zh.htm

    pom文件如下

    <projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd">

     <modelVersion>4.0.0</modelVersion>
     <parent>
      <groupId>com.home</groupId>
      <artifactId>oa-parent</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <relativePath>../oa-parent/pom.xml</relativePath>
     </parent>
     <artifactId>oa-web-boss2</artifactId>
     <packaging>war</packaging>
     <build>
     <resources>
    <resource>
    <targetPath>${project.build.directory}/classes</targetPath>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
    <includes>
    <include>**/*.xml</include>
    <include>**/*.properties</include>
    </includes>
    </resource>
    </resources>
     </build>
     <dependencies>
     <dependency>
       <groupId>com.home</groupId>
       <artifactId>oa-facade</artifactId>
       <version>${oa-facade.version}</version>
    </dependency>
    <dependency>
    <groupId>commons-pool</groupId>
    <artifactId>commons-pool</artifactId>
    <version>1.6</version>
    </dependency>
    <dependency>
       <groupId>com.home</groupId>
       <artifactId>oa-common-config</artifactId>
       <version>${oa-common-config.version}</version>
    </dependency>
       <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>dubbo</artifactId>
    <version>${dubbo.version}</version>
    <exclusions>
    <exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>com.github.sgroschupf</groupId>
    <artifactId>zkclient</artifactId>
    <version>${zkclient.version}</version>
    </dependency>
    <dependency>
    <groupId>org.apache.zookeeper</groupId>
    <artifactId>zookeeper</artifactId>
    <version>${zookeeper.version}</version>
    <exclusions>
    <exclusion>
    <artifactId>jmxtools</artifactId>
    <groupId>com.sun.jdmk</groupId>
    </exclusion>
    <exclusion>
    <artifactId>jmxri</artifactId>
    <groupId>com.sun.jmx</groupId>
    </exclusion>
    <exclusion>
    <artifactId>jms</artifactId>
    <groupId>javax.jms</groupId>
    </exclusion>
    </exclusions>
    </dependency>
    <!--spring-->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <exclusions>
    <exclusion>
    <artifactId>commons-logging</artifactId>
    <groupId>commons-logging</groupId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    </dependency>
     </dependencies>
    </project>

    dubbo-consumer.xml文件如下:

    <?xmlversion="1.0"encoding="UTF-8"?>

    <beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd 
        http://code.alibabatech.com/schema/dubbo 
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">


    <!--消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样-->
    <dubbo:applicationname="oa-web-boss"/>


    <!--使用zookeeper注册中心暴露服务地址-->
    <!--注册中心地址-->
    <dubbo:registryprotocol="zookeeper"address="127.0.0.1:2181"/>

    <!--用户服务接口-->
    <dubbo:referenceinterface="com.home.service.UserService"id="userService"check="false"/>


    </beans> 

    spring-mvc.xml文件如下:

    <?xmlversion="1.0"encoding="UTF-8"?>
    <beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
          http://www.springframework.org/schema/aop  
          http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.2.xsd"
    default-autowire="byName"default-lazy-init="false">


    <!--采用注释的方式配置bean-->
    <context:annotation-config/>
    <mvc:annotation-driven/>

    <!--配置要扫描的包-->
    <context:component-scanbase-package="com.home"/>

    <!--定义跳转的文件的前后缀,视图模式配置-->
    <beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <!--这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个可用的url地址-->
    <propertyname="prefix"value="/"/>
    <propertyname="suffix"value=".jsp"/>
    </bean>


    </beans>

    web.xml如下:

    <?xmlversion="1.0"encoding="UTF-8"?>
    <web-appversion="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
     <display-name>ArchetypeCreatedWebApplication</display-name>
     <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/dubbo-consumer.xml</param-value>
    </context-param>
    <!--编码过滤器-->
    <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <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>
    <!--Spring监听器-->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!--防止Spring内存溢出监听器-->
    <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>


    <!--SpringMVCservlet-->
    <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/spring-context.xml</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>SpringMVC</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
     <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
     </welcome-file-list>
    </web-app>


    我猜是spring的配置和dubbo的配置加载顺序的问题,加载dubbo之前必须先加载bean配置,否则就会出现ClassNotFound.你试试将bean的配置加到dubbo配置的第一行看看结果

    回复 @liujl110:请问你后来是怎么解决的呢?我也遇到了一样的问题会不会是打包的问题,我没有打包,只配置了依赖我使用mavenclean,然后用maveninstall会报:还是不可以
    2020-06-09 15:50:42
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Dubbo开源现状与2.7规划 立即下载
Dubbo分布式服务治理实战 立即下载
《Dubbo 3.0 前瞻》 立即下载