Java 将Spring Web应用程序部署到JBoss WebApplicationContext异常

Java 将Spring Web应用程序部署到JBoss WebApplicationContext异常,java,spring,servlets,jboss,Java,Spring,Servlets,Jboss,将Spring Web应用程序部署到JBoss 7.1.1时,会出现以下异常: 12:26:58,053 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/i]] (MSC service thread 1-3) Exception sending context initialized event to listener instance of class com.listener.IListe

将Spring Web应用程序部署到JBoss 7.1.1时,会出现以下异常:

12:26:58,053 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/i]] (MSC service thread 1-3) Exception sending context initialized event to listener instance of class com.listener.IListener: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:84) [spring-web-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at com.listener.IListener.contextInitialized(IListener.java:28) [classes:]
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]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_26]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]

12:26:58,115 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-3) Error listenerStart
12:26:58,115 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-3) Context [/i] startup failed due to previous errors
12:26:58,131 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.web.deployment.default-host./i: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./i: JBAS018040: Failed to start context
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:95)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_26]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]

12:26:58,146 INFO  [org.jboss.as] (MSC service thread 1-7) JBAS015951: Admin console listening on http://127.0.0.1:9990
12:26:58,146 ERROR [org.jboss.as] (MSC service thread 1-7) JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors) in 4883ms - Started 225 of 304 services (2 services failed or missing dependencies, 76 services are passive or on-demand)
12:26:58,365 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "webchannel.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host./i" => "org.jboss.msc.service.StartException in service     jboss.web.deployment.default-host./i: JBAS018040: Failed to start context"}}
12:26:58,521 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment webchannel.war in 161ms
 12:26:58,521 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.web.deployment.default-host./i: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./i: JBAS018040: Failed to start context

   12:26:58,536 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host./i" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./i: JBAS018040: Failed to start context"}}}}
我有一个叫IListener的ServletContextListener。当我尝试访问WebApplicationContext时,我收到上述异常。然而,这在我看来是可行的

代码如下:

public class IListener implements ServletContextListener {

public IListener() {

}

public void contextInitialized(ServletContextEvent event) {
    ServletContext context = event.getServletContext();
    WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
    }

public void contextDestroyed(ServletContextEvent event) {

}
  }
web.xml

<?xml version="1.0" encoding="UTF-8"?>

http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd" version=“2.5”>

JEE WebApp
上下文配置位置
/WEB-INF/spring/services.xml
org.springframework.web.context.ContextLoaderListener
com.listener.IListener
我
org.springframework.web.servlet.DispatcherServlet
1.
我
/
index.jsp

Java版本为1.6,Spring版本为3.0.6.0


我不知道该怎么办。

通常,Spring的
ContextLoaderListener
很好用。如果您没有任何具体要求,就使用它。总之,它应该是这样的:

 <listener>
    <!-- Loads your Configuration Files-->
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

org.springframework.web.context.ContextLoaderListener

如果您需要使用Spring上下文的侦听器,可以考虑扩展该类。请确保<代码> CONTRONEXPREALIZED()/Cux>方法首先调用<代码> Super 实现(以便它可以为您初始化Spring上下文)。之后,它将通过<代码>(WebAppultEnror)获得。servletContext.getAttribute(WebApplicationContext.ROOT\u WEB\u APPLICATION\u CONTEXT\u ATTRIBUTE)。但是,您的

contextDestroyed()
方法应该首先执行自己的逻辑,最后调用其超级实现

但是,请注意,从这个角度来看,这不是一个非常干净的解决方案


如果可能的话,我的建议是使用Spring筛选器、侦听器或。它们由Spring自动连接,您可以在它们内部使用完整的Spring功能。

事实上,我需要有自己的侦听器。我可以从日志中看到event.getServletContext()有效。只有当WebApplicationContext WebApplicationContext=WebApplicationContextils.getRequiredWebApplicationContext(上下文)出现问题时,您的侦听器才需要初始化Spring上下文本身?或者您可以构建一个,例如?侦听器需要初始化Spring上下文本身。
 <listener>
    <!-- Loads your Configuration Files-->
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>