不知何故,项目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
答案 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.xml
和spring-database.xml
文件位于目录examples/spring
下的B.jar文件中