Spring XML文件中导入位于jar包中的XML文件

在基于Spring构建的项目中,我们都知道核心的Context配置文件是ApplicationContext.xml或者{projectName}-serverlet.xml, 如果我们想拆分配置文件,那么只需在核心的配置文件中import其它的几个配置文件即可。

 

举例说明:如果当前的项目名称为cms-validator,我们假定现在Spring的核心的Context配置文件是:

cms-validator-servlet.xml.我们可以在这个配置文件中导入其它的配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       ">
    
    <import resource="cms-validator-common.xml"/>
    <import resource="cms-validator-hibernate.xml"/>
    <import resource="cms-validator-service.xml"/>
    <import resource="cms-validator-dao.xml"/>

     
</beans>

 

很显然,上面的方案是这些配置文件和当前的配置文件都在一个project的同一个目录中,那么如果我们想导入的配置文件在jar包,怎么处理?假设这几个配置文件在validator-rest-1.0.jar中,则可以用

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       ">
    

    <import resource="lib/validator-rest-1.0.jar*/cms-validator-common.xml"/>
    <import resource="lib/validator-rest-1.0.jar*/cms-validator-hibernate.xml"/>
    <import resource="lib/validator-rest-1.0.jar*/cms-validator-service.xml"/>
    <import resource="lib/validator-rest-1.0.jar*/cms-validator-dao.xml"/>
     
</beans>

 

只要用*号,就可以完成从jar包中import文件。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值