tags:

views:

856

answers:

1

I'm trying to use Spring to configure a web app deployed in JBoss. I've added this to the web.xml:

<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

However, I've based my config on the 'default' JBoss config that includes wars such as jmx-console.war, and now these fail to deploy with the error:

[ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

So how can I tell ContextLoaderListener to ignore this error, or at least bypass these particular wars, while still attempting to process my own wars?

+1  A: 

You must have your application context at /WEB-INF/applicationContext.xml. As this is application-specific, it should be configured for your applications, not other applications. That is, don't map the ContextLoaderListener at an application server level.

You CAN setup an alternative location, using:

<context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>
         /WEB-INF/mylocation/spring.xml
     </param-value>
</context-param>

But you can't (and you must not) ignore it.

Bozho
I'm not sure I'm following you... are you saying that I must add a /WEB-INF/applicationContext.xml to ALL the .war files, even if it is just an empty file? The jboss default setup includes 6 wars: admin-console.war, http-invoker.sar/invoker.war, jbossws.sar/jbossws-management.war, jmx-console.war, management/console-mgr.war, and ROOT.war. I have worked around the problem by doing this (adding an empty applicationContext.xml), it just seems kind of hackish to have to change these .wars that come with jboss by default and will never have any spring config.
Kevin Pauli
No, I meant you must have ContextLoaderListener declared only for your application, not for all
Bozho
Oh! For some reason I was under the misconception that the only place you could add filters was in the web.xml under jbossweb.deployer. Thanks, that of course is the correct solution!
Kevin Pauli