Skip to content

Application can't be started because of DubboWebApplicationInitializer #1998

Closed

Description

@ATAKing1023

DubboWebApplicationInitializer will create a root application context, which is conflict with the SpringContextLoaderListener in webxml. See attached stacktrace and web configuration for detail.

P.S. Running dubbo web application in JBoss EAP 6.

exception-stacktrace.txt

12:48:06,305 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/naoms.server]] (ServerService Thread Pool -- 7) JBWEB000287: 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:296) [spring-web-4.3.16.RELEASE.jar:4.3.16.RELEASE]
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) [spring-web-4.3.16.RELEASE.jar:4.3.16.RELEASE]
	at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3339) [jbossweb-7.5.26.Final-redhat-1.jar:7.5.26.Final-redhat-1]
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:3780) [jbossweb-7.5.26.Final-redhat-1.jar:7.5.26.Final-redhat-1]
	at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:163) [jboss-as-web-7.5.18.Final-redhat-1.jar:7.5.18.Final-redhat-1]
	at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:61) [jboss-as-web-7.5.18.Final-redhat-1.jar:7.5.18.Final-redhat-1]
	at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:96) [jboss-as-web-7.5.18.Final-redhat-1.jar:7.5.18.Final-redhat-1]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0_131]
	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [rt.jar:1.8.0_131]
	at java.util.concurrent.FutureTask.run(FutureTask.java) [rt.jar:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_131]
	at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_131]
	at org.jboss.threads.JBossThread.run(JBossThread.java:122)

web-xml.txt

<?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">
	<display-name>fims.webappserver</display-name>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<!-- Dubbo Configuration -->
		<param-value>classpath:base-context.xml,classpath:base-dubbo.xml,classpath:dubbo-provider.xml
		</param-value>
	</context-param>
</web-app>

Activity

  1. added a commit that references this issue on Jun 28, 2018
  2. ralf0131 commented on Jun 28, 2018

    @ralf0131
    Contributor

    Thanks for reporting, I am planning to look into it in the next one to two days.

  3. ralf0131 commented on Jul 1, 2018

    @ralf0131
    Contributor

    Hi, I think removing SpringContextLoaderListener in your web.xml will solve this issue. But that will require user to change their code.

    The DubboWebApplicationInitializer will be called before any Listener configured in web.xml.

    I am still thinking about a more elegant way to solve it.

  4. ATAKing1023 commented on Jul 2, 2018

    @ATAKing1023
    ContributorAuthor

    Is it possible for dubbo to implement it's own ServletContextListener?

    1. For web application, just a bit more configuration is required.
    2. For Java SE application (e.g. JavaFX, a java client technology), the current approach ( add shutdown hook in AbstractConfig) is appreciated.
  5. ralf0131 commented on Jul 2, 2018

    @ralf0131
    Contributor

    Is it possible for dubbo to implement it's own ServletContextListener?

    Yes. But that also requires user to change their configuration. Actually it is possible to configure the DubboApplicationListener in your applicationContext.xml or using annotations.

    The primary concern here is how to enable that feature without user being aware of it. So I use the ServletContainerInitializer to implement that.

    If you check the source code of org.springframework.web.context.AbstractContextLoaderInitializer#registerContextLoaderListener

    	protected void registerContextLoaderListener(ServletContext servletContext) {
    		WebApplicationContext rootAppContext = createRootApplicationContext();
    		if (rootAppContext != null) {
    			ContextLoaderListener listener = new ContextLoaderListener(rootAppContext);
    			listener.setContextInitializers(getRootApplicationContextInitializers());
    			servletContext.addListener(listener);
    		}
    		else {
    			logger.debug("No ContextLoaderListener registered, as " +
    					"createRootApplicationContext() did not return an application context");
    		}
    	}

    You will find that it does the same thing for you. So you will not need to specify the ContextLoaderListener anymore.

    So I am suggesting that you remove the ContextLoaderListener configuration in your web.xml. Does that make sense?

  6. ralf0131 commented on Jul 11, 2018

    @ralf0131
    Contributor

    Hi, I am closing this issue for now, please reopen it if you still encounter any issue.

  7. ralf0131 commented on Jul 24, 2018

    @ralf0131
    Contributor

    Hi, I think this issue will break the compatibility if user is going to upgrade to 2.6.3 or above, so I am going to re-open it.

  8. self-assigned this
    on Jul 24, 2018
  9. added this to the 2.6.3 milestone on Jul 26, 2018
  10. added a commit that references this issue on Jul 26, 2018
    ee21cea
  11. ralf0131 commented on Jul 26, 2018

    @ralf0131
    Contributor

    Hi, @ATAKing1023 Your problem will fixed in 2.6.3. Please help to check in 2.6.3-release branch, or when we are doing release vote in the mailing list.

  12. ATAKing1023 commented on Jul 26, 2018

    @ATAKing1023
    ContributorAuthor

    I will verify and comment later. Thank you.

  13. added a commit that references this issue on Sep 10, 2019
    116c9c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions