views:

400

answers:

2

In a web-app, we define the context config location for spring to initialize all the beans like this

 <!-- Spring Application Configuration -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/spring/ctx-*.xml</param-value>
 </context-param>
 <listener>
  <description>Spring Context Listener</description>
  <display-name>SpringContextListener</display-name>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

I am trying to find out, if it is possible to do that inside a jar file (containing all the spring beans) where I donot have a web.xml?

A: 

you can use the prefix 'classpath:'

classpath:ctx-*.xml

see http://static.springsource.org/spring/docs/2.5.6/reference/resources.html#resources-app-ctx

Stefan De Boey
But where do I specify the <context-param/>? Can I specify inside one of the ctx-* files?
subh
I checked the XSD, it doesn't define <context-param/>http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
subh
if you want to use this without web.xml, then you should create the application context yourselves. in that initialization code you can use the 'classpath:' prefix to load config files packaged in your jar
Stefan De Boey
A: 

You can add a delegation level put /WEB-INF/spring/my-aggregator-context.xml

which is a placeholder xml file which does a "import classpath:ctx*-xml"

If you have multiple appContext.xml in many jars and you want all included then you could even say classpath*:appContext.xml

Calm Storm