Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 作为EAR的一部分部署web应用时出现多个ContextLoader*定义异常_Java_Spring Mvc_Jboss7.x - Fatal编程技术网

Java 作为EAR的一部分部署web应用时出现多个ContextLoader*定义异常

Java 作为EAR的一部分部署web应用时出现多个ContextLoader*定义异常,java,spring-mvc,jboss7.x,Java,Spring Mvc,Jboss7.x,更新1:我的JBoss中可能有一些剩余文件(不确定如何),因为它现在可以工作了 我将为我的Spring MVC web应用程序开发新的应用程序。当我将它部署到Jetty时,它工作得很好。然而,当我将其作为EAR的一部分部署时,它会抱怨web.xml中有多个ContextLoader*定义,而我甚至没有这些定义 我的代码: public class WebInitializer implements WebApplicationInitializer { @Override pub

更新1:我的JBoss中可能有一些剩余文件(不确定如何),因为它现在可以工作了

我将为我的Spring MVC web应用程序开发新的应用程序。当我将它部署到Jetty时,它工作得很好。然而,当我将其作为EAR的一部分部署时,它会抱怨web.xml中有多个ContextLoader*定义,而我甚至没有这些定义

我的代码:

public class WebInitializer implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext container) {
      // Create the 'root' Spring application context
      AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
      rootContext.register(WebConfig.class);

      // Manage the lifecycle of the root application context
      container.addListener(new ContextLoaderListener(rootContext));

      // Register and map the dispatcher servlet
      ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(rootContext));
      dispatcher.setLoadOnStartup(1);
      dispatcher.addMapping("/");
    }
}

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.acme.web.controller"}) //picks up TestController below.
public class WebConfig extends WebMvcConfigurerAdapter {
    //It's actually empty
}

public class TestController {

    @RequestMapping(value = "/testThisApp")
    public String testThisApp(){

        return "testThisApp";
    }
}
例外情况:

[org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/app-web]] (MSC service thread 1-7) 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:264) [spring-web-3.1.0.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) [spring-web-3.1.0.RELEASE.jar:4.1.7.RELEASE]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]