java引用xml_java – 如何在spring中引用另一个xml文件的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应用程序,您可以在web.xml中执行:

contextConfigLocation

WEB-INF/conf/spring/this-xml-conf.xml

WEB-INF/conf/spring/that-other-xml-conf.xml

org.springframework.web.context.ContextLoaderListener

如果它是一个独立的应用程序,库等。您将加载您的ApplicationContext为:

new ClassPathXmlApplicationContext(

new String[] { "classpath:META-INF/conf/spring/this-xml-conf.xml",

"classpath:META-INF/conf/spring/that-other-xml-conf.xml" } );

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值