春天如何引用另一个xml文件的bean

春天如何引用另一个xml文件的bean,第1张

春天如何引用另一个xml文件的bean

您有两种选择:

进口
<import resource="classpath:config/spring/that-other-xml-conf.xml"/><bean id="yourCoolBean" >    <property name="anotherBean" ref="thatOtherBean"/></bean>
包括在
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 {...}

如果它是一个网络应用程序,则可以在中进行

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>

如果它是独立的应用程序,库等,则应将其加载

ApplicationContext
为:

new ClassPathXmlApplicationContext(     new String[] { "classpath:meta-INF/conf/spring/this-xml-conf.xml",        "classpath:meta-INF/conf/spring/that-other-xml-conf.xml" } );


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5488658.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存