簡體   English   中英

初始化封裝在jar文件中的Spring bean

[英]Initialize Spring beans packaged inside a jar file

在web-app中,我們為spring定義上下文配置位置以初始化所有這樣的bean

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

你可以使用前綴'classpath:'

classpath:ctx-*.xml

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

您可以添加委派級別put /WEB-INF/spring/my-aggregator-context.xml

這是一個占位符xml文件,它執行“import classpath:ctx * -xml”

如果您在許多jar中有多個appContext.xml,並且您想要包含所有內容,那么您甚至可以說classpath *:appContext.xml

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM