2010-03-04 101 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