2010-03-04 91 views
5

在一个web应用程序内包装的初始化春豆,我们定义范围内的配置位置春天初始化所有这样一个jar文件

<!-- 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> 

豆我试图找到答案,如果可能的话在一个jar文件里面(包含所有的spring bean),在那里我没有web.xml文件?

回答

3

您可以使用前缀 '类路径:'

classpath:ctx-*.xml 

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

+0

但我在哪里指定?我可以在一个ctx- *文件中指定吗? – subh 2010-03-04 23:31:59

+0

我检查了XSD,它没有定义 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd – subh 2010-03-04 23:36:02

+0

如果你想使用这个没有网页。 xml,那么你应该自己创建应用程序上下文。在初始化代码中,您可以使用'classpath:'前缀来加载打包在jar中的配置文件 – 2010-03-04 23:49:51

0

您可以添加一个代表团级别放 /WEB-INF/spring/my-aggregator-context.xml

这是一个占位符xml文件,它执行“导入类路径:ctx * -xml”

如果在多个jar中有多个appContext.xml s和你想要所有包括,那么你甚至可以说classpath *:appContext.xml