SingletonBeanFactoryLocator找不到位于另一个JAR中的XML文件

时间:2012-02-23 02:42:01

标签: spring

不知何故,项目A无法读取项目B的 spring.xml spring-database.xml 文件。

项目B位于EAR项目A的相同APP-INF / lib内。

* 项目A *

应用的myproject-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="examples.spring" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list>
<value>examples/spring/**spring.xml**</value>
<value>examples/spring/**spring-database.xml**</value>
</list>
</constructor-arg>
</bean>
</beans>

客户端代码......

BeanFactoryLocator bfLocator = SingletonBeanFactoryLocator.getInstance();
BeanFactoryReference bfReference = bfLocator.useBeanFactory("examples.spring");
BeanFactory factory = bfReference.getFactory();
DataSource dataSource = (DataSource) factory.getBean("dataSource");

* 项目B *

spring.xml
spring-database.xml

1 个答案:

答案 0 :(得分:0)

尝试使用'classpath'关键字:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="examples.spring" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list>
<value>classpath:/examples/spring/spring.xml</value>
<value>classpath:/examples/spring/spring-database.xml</value>
</list>
</constructor-arg>
</bean>
</beans>

假设spring.xmlspring-database.xml文件位于目录examples/spring下的B.jar文件中