---
title: "spring加载jar包中多个配置文件"
author: "evan0625"
date: "2012-07-18T18:48:08Z"
tags: []
categories: ["企业架构"]
slug: "spring-jar"
draft: false
lastmod: "2012-07-21T18:09:09Z"
id: 1598366
url: "https://evan0625.iteye.com/blog/1598366"
---

在使用spring加载jar包中的配置文件时，不支持通配符，需要一个一个引入，如下所示：

```
<context-param>   
  <param-name>contextConfigLocation</param-name>   
  <param-value>   
    classpath*:beanconfigs/applicationContext_1.xml,   
    classpath*:beanconfigs/applicationContext_2.xml,
    ...   
  </param-value>   
</context-param> 
```

 

这样太复杂了，对于一个大的项目而言，要在这里写入太多的配置，影响美观还害怕引入的xml减少。可以自定义一个applicationContext\_all.xml，使用import引入其他配置文件，如下所示：

```
<import resource="beanconfigs/applicationContext_1.xml" />
<import resource="beanconfigs/applicationContext_2.xml" />
...
```

可以使用通配符设置，如下所示：

```
<import resource="beanconfigs/applicationContext_*.xml" />
```

 

这样在spring配置就可以写成如下所示：

```
<context-param>   
  <param-name>contextConfigLocation</param-name>   
  <param-value>   
    classpath*:applicationContext_all.xml  
  </param-value>   
</context-param> 
```