Skip to content

spring boot with dubbo 2.6.3, cause ‘ Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml’ #2535

Closed

Description

@iorilchen

Environment

  • Dubbo version: 2.6.3
  • Operating System version: Linux ubuntu 4.9.0
  • Java version: 1.8
  • tomcat-7.0.82.4
  • spring boot 2.0.1.RELEASE

Steps to reproduce this issue

a web spring boot project use dubbo as a consumer,when deploy it to tomcat-7.0.82.4 ,start the applicaton failed, but it start success in IDE without tomcat

Pls. provide [GitHub address] to reproduce this issue.

Expected Result

web project start success

Actual Result

failed

If there is an exception, please attach the exception trace:

[ERROR] - Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:262)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5110)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5633)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1015)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:991)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1296)
        at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2038)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

Activity

  1. chenlushun commented on Sep 20, 2018

    @chenlushun
    Contributor

    这个问题跟DUBBO没关系吧?
    你检查一下,web.xml 里面是不是配置了ContextLoaderListener?Spring boot是不需要配置ContextLoaderListener的

  2. iorilchen commented on Sep 20, 2018

    @iorilchen
    Author

    我这个工程spring boot里没有web.xml。 在intellij里启动main可以,发布到tomcat 里启动就报这个。回退到之前一直用的2.6.2就好了。还没来得及进一步分析原因

  3. zxbu commented on Sep 20, 2018

    @zxbu

    有同样问题,回退到2.6.2就好了,未有任何改动。

  4. hujiachenn commented on Sep 30, 2018

    @hujiachenn

    回退到2.6.2可以 , 2.6.3 tomcat9启动报内存溢出

  5. kexianjun commented on Oct 4, 2018

    @kexianjun
    Member

    May be the same problem as #2538

  6. iorilchen commented on Oct 11, 2018

    @iorilchen
    Author

    ApplicationContextHolder implements ApplicationContextAware
    怀疑是
    applicationContext.xml里配置了

    引起。 在filter里要拿bean,如果是dubbo provider端可以用ServiceBean.getSpringContext().getBean(),
    但如果是web客户端,ServiceBean.getSpringContext()为空,为了拿到applicationContext.xml配置的bean,就要用到applicationContextHolder

  7. beiwei30 commented on Oct 31, 2018

    @beiwei30
    Member

    It's been addressed by ee21cea on 2.6.x and 393ffce on 2.7

  8. zhangsongyang commented on Feb 25, 2019

    @zhangsongyang

    有同样问题,回退到2.6.2就好了,未有任何改动。但是为什么2.6.5就不行

  9. saillen commented on Mar 5, 2019

    @saillen

    dubbo 2.6.3 默认添加了 web-fragment.xml,这个特性基于 servlet 3.0 ,容器会自动扫描这个文件,dubbo-fragment.xml 里面添加一个ContextLoaderListener。Spring Boot 2.0 也基于 Servlet 3.0 添加这个listener,这样就会报错,算是Dubbo的bug。添加一个web.xml 关闭这个特性就好了。

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