Skip to content

dubbo all in one fail to start from a tomcat server when spring framework is absent #2570

Closed

Description

@yangfuhai

错误如下:

27-Sep-2018 13:39:35.736 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
	at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:520)
	at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:501)
	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:120)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
	at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1678)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399)
	at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:828)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
	at sun.rmi.transport.Transport$1.run(Transport.java:178)
	at sun.rmi.transport.Transport$1.run(Transport.java:175)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:174)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:557)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:812)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:671)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

maven依赖如下:

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>dubbo</artifactId>
    <version>2.6.3</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Activity

  1. diecui1202 commented on Sep 27, 2018

    @diecui1202

    @yangfuhai could u pls. provide a demo to reproduce this problem?

  2. yangfuhai commented on Sep 27, 2018

    @yangfuhai
    Author

    @yangfuhai could u pls. provide a demo to reproduce this problem?

    已经定位到问题,原因是当排除spring依赖后,dubbo 2.6.3 下有web-fragment.xml文件,web-fragment.xml会自动去加载 org.springframework.web.context.ContextLoaderListener 导致tomcat无法正常启动。

    建议修改:

    ContextLoaderListener 修改为 DubboContextLoaderListener,在 DubboContextLoaderListener 里去查看spring是否存在,存在就启动spring 的 ContextLoaderListener,否则什么都不做。

  3. diecui1202 commented on Sep 27, 2018

    @diecui1202

    @ralf0131 pls. check this problem.

  4. ralf0131 commented on Sep 27, 2018

    @ralf0131
    Contributor

    If you don't run Dubbo with Tomcat + spring, then don't need this file. If file is intended to bed used for Dubbo + Tomcat + Spring.

    Please remove the dependency to dubbo-config-spring

  5. diecui1202 commented on Sep 27, 2018

    @diecui1202

    I think he uses com.alibaba:dubbo, all in one jar, so can not exclude this dependency.

  6. yangfuhai commented on Oct 6, 2018

    @yangfuhai
    Author

    I think he uses com.alibaba:dubbo, all in one jar, so can not exclude this dependency.

    之前的版本并没有这个问题。2.6.3 才有的。

  7. ralf0131 commented on Oct 7, 2018

    @ralf0131
    Contributor

    @yangfuhai In this case, please don't depend on the all in one dependency.

        <groupId>com.alibaba</groupId>
        <artifactId>dubbo</artifactId>
        <version>2.6.3</version>

    And try to depend on the specific module you wish to use, e.g.

        <groupId>com.alibaba</groupId>
        <artifactId>dubbo-config-api</artifactId>
        <version>2.6.3</version>
  8. ralf0131 commented on Oct 7, 2018

    @ralf0131
    Contributor

    @diecui1202

    I think he uses com.alibaba:dubbo, all in one jar, so can not exclude this dependency.

    Why we need to shade all the dependency into one jar? This make it difficult to customize the dependency.
    I think this is something worth discussion.

  9. SKYhuangjing commented on Oct 12, 2018

    @SKYhuangjing

    @diecui1202

    I think he uses com.alibaba:dubbo, all in one jar, so can not exclude this dependency.

    Why we need to shade all the dependency into one jar? This make it difficult to customize the dependency.
    I think this is something worth discussion.

    provide dubbo-all-without-spring module, just like dubbo-all, but dubbo-all-without-spring module did't rely spring-framework and have no dubbo-xxx-spring module

    I have forked dubbo repo and make dubbo-all-without-spring module in mine repo.

    if offical don't provide, you can make it yourself.

  10. ralf0131 commented on Oct 12, 2018

    @ralf0131
    Contributor

    Hi,

    I would suggest to use maven profile to do this kind of customization.

    For example, use the default profile for most of the dependencies, and use spring profile to include spring dependency.

  11. changed the title [-]dubbo无法在 【非spring + tomcat】环境下运行[/-] [+] dubbo all in one fail to start from a tomcat server when spring framework is absent[/+] on Oct 12, 2018
  12. beiwei30 commented on Oct 12, 2018

    @beiwei30
    Member

    @yangfuhai, would you mind to try out the change I proposed in #2640

  13. ralf0131 commented on Oct 12, 2018

    @ralf0131
    Contributor

    Hi,

    As another work-around, you may try to skip the annotation scan for dubbo-all.jar, so that this org.springframework.web.context.ContextLoaderListener won't be scaned or loaded.

    Read this see Configure your web application and Exclude JARs from scanning section for more details.

  14. SKYhuangjing commented on Oct 14, 2018

    @SKYhuangjing

    provide dubbo-all can be easy integrate to our app, if no dubbo-all, we have to need rely multi dubbo-xxx, it's not easy job(That is very painful for rookie(just like me...))
    and may be dev don't wanna change the tomcat(or wildfly), in my humble opinion, this work is also more hardly.
    as a middleware, i hope dubbo can provide a more easy usage option in non-spring runtime.,just like dubbo-all module. Of course this may be based on the fact that I am a rookie and I hope that the integrated dubbo upgrade can be easier.

  15. beiwei30 commented on Oct 15, 2018

    @beiwei30
    Member

    @SKYhuangjing @yangfuhai I believe I've finalized the solution I proposed in pull request
    #2640, would you mind to try it out?

  16. added a commit that references this issue on Oct 16, 2018
  17. beiwei30 commented on Feb 11, 2019

    @beiwei30
    Member

    it's been fixed.

  18. SKYhuangjing commented on Feb 14, 2019

    @SKYhuangjing

    i have upgraded dubbo version to 2.7.0, it's good solution for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions