---
title: "spring import  jar中的bean配置文件"
author: "lionbule"
date: "2012-06-12T17:28:22Z"
tags: ["Spring", "import"]
categories: ["编程语言"]
slug: "spring-import-jar-bean"
draft: false
lastmod: "2012-06-12T17:28:22Z"
id: 1559267
url: "https://lionbule.iteye.com/blog/1559267"
---

在spring中import resource file，有两种情况：classes目录和jar包

 

如果资源文件在classes目录：

&lt;import resource="classpath:xxx.xml" /&gt;

备注：

1、目录下的文件 如：classes/bean/test.xml

     &lt;import resource="classpath:bean/test.xml" /&gt;

 

如果资源文件在jar包中：

&lt;import resource="classpath\*:xxx.xml" /&gt;

1、注意在classpath后加\*号

2、如果加载jar包中某个目录下的文件，如下

     &lt;import resource="classpath\*:bean/test.xml" /&gt;

 

Reference：

[http://stackoverflow.com/questions/1601106/relative-paths-in-spring-classpath-resource](http://stackoverflow.com/questions/1601106/relative-paths-in-spring-classpath-resource)