tol*_*ius 54
你有几个选择:
<import resource="classpath:config/spring/that-other-xml-conf.xml"/>
<bean id="yourCoolBean" class="org.jdong.MyCoolBean">
<property name="anotherBean" ref="thatOtherBean"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
ApplicationContext建筑中ApplicationContext在创建文件时将这两个文件作为您的一部分=>然后不需要导入.
例如,如果您在测试期间需要它:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:META-INF/conf/spring/this-xml-conf.xml",
"classpath:META-INF/conf/spring/that-other-xml-conf.xml" })
public class CleverMoneyMakingBusinessServiceIntegrationTest {...}
Run Code Online (Sandbox Code Playgroud)
如果它是一个Web应用程序,您可以在web.xml以下位置执行:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/conf/spring/this-xml-conf.xml</param-value>
<param-value>WEB-INF/conf/spring/that-other-xml-conf.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
如果它是一个独立的应用程序,库等..你会加载你ApplicationContext的:
new ClassPathXmlApplicationContext(
new String[] { "classpath:META-INF/conf/spring/this-xml-conf.xml",
"classpath:META-INF/conf/spring/that-other-xml-conf.xml" } );
Run Code Online (Sandbox Code Playgroud)
只需导入定义bean的xml <import resource="otherXml.xml">,就可以使用bean定义了.
您可以classpath:在resource属性中使用:
<import resource="classpath:anotherXXML.xml" />
Run Code Online (Sandbox Code Playgroud)
请参阅Spring Reference的本章中的"3.18.将Bean定义从一个文件导入另一个文件"
| 归档时间: |
|
| 查看次数: |
77420 次 |
| 最近记录: |