一个Web应用有多个模块(假设有org和auth两个模块), 我希望为每个模块创建一个项目, 在项目中维护模块用到的配置文件. 然后将这些模块分别打包成jar放到web应用的WEB-INF/lib下.
现在用单元测试, 在Web应用中运行单元测试, 如果在Web应用的Build Path/Project中添加模块项目, 单元测试能够成功, 如果使用Build Path/Libraries添加模块jar文件, 运行单元测试失败. Spring中加载配置文件代码如下:
[code="xml"]
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
classpath*:/config/hibernate/app/
classpath*:/config/hibernate/framework/
...
[/code]
每个jar包里面都有/config/hibernate/framework文件夹
错误信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'menuService' defined in URL [jar:file:/E:/home/workspaces/eclipse/simple-web/WebContent/WEB-INF/lib/auth.jar!/config/spring/app/services.xml]: Cannot resolve reference to bean 'defaultMediator' while setting bean property 'defautMediator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultMediator' defined in class path resource [config/env/base-dao.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [config/persistence/hibernate.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: URL [jar:file:/E:/home/workspaces/eclipse/simple-web/WebContent/WEB-INF/lib/auth.jar!/config/hibernate/framework/] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/E:/home/workspaces/eclipse/simple-web/WebContent/WEB-INF/lib/auth.jar!/config/hibernate/framework/
网上找到一个相关的讨论: http://forum.springframework.org/archive/index.php/t-10029.html
好像是说对于directory的加载必须是文件夹必须存在于文件系统中, jar下面的文件夹找不到.不知道这个问题有没有办法解决?
谢谢先!
ps. 第一次提问, 如果有不当之处请各位包涵
[b]问题补充:[/b]
感谢czlonly的回答, 不过能不能写详细一点?
我刚才试了一下, 如果把配置文件改成
[code="xml"]
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
classpath*:/config/hibernate/framework/*.xml
...
[/code]
果然可以了