2013-07-23 14 views
0

在部署的Spring Web應用程序到JBoss 7.1.1,給出了以下異常:部署春季萬維網應用程序到JBoss的WebApplicationContext例外

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時,我收到上述異常。但是,這在TomEE中起作用。

下面是代碼:

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」 版本= 「2.5」>

 <display-name>JEE WebApp</display-name> 

    <context-param> 
     <!-- Specifies the list of Spring Configuration files in comma separated format.--> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
     /WEB-INF/spring/services.xml</param-value> 
    </context-param> 

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

    <servlet> 
     <servlet-name>i</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>i</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list>  

Java版本是1.6和Spring版本3.0.6.RELEASE。

我不知道該怎麼做。

回答

0

通常,來自Spring的ContextLoaderListener是很好去。如果您沒有任何特定要求,請使用該要求。所有功能於一切,這應該是這樣的:

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

如果你需要有一個使用Spring上下文監聽器,你可以考慮擴大這一類。確保contextInitialized()方法首先調用super實現(以便它可以爲你初始化Spring上下文)。之後,它將通過(WebApplicationContext) servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)提供。但是,您的contextDestroyed()方法應首先執行自己的邏輯並最終調用其超級實現。

但是請注意,從"seperation of concerns"的角度來看,這不是一個非常乾淨的解決方案。

我的建議是,如果可能的話,使用Spring過濾器,聽衆或Interceptors。它們由Spring自動自動裝配,你可以在它們內部使用完整的Spring電源。

+0

其實,我有一個要求有我自己的聽衆。 – user1646481

+0

我可以從日誌中看到event.getServletContext()的工作原理。只有當WebApplicationContext的webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context)出現問題時。 – user1646481

+0

而你的監聽器需要初始化Spring上下文本身?或者你可以建立一個['ApplicationListener'](http://learningviacode.blogspot.nl/2012/07/spring-and-events-and-listeners.html),例如? – mthmulders