在依赖项 A 中,我有以下内容:
<beans>
<bean
id="simplePersonBase"
class="com.paml.test.SimplePerson"
abstract="true">
<property
name="firstName"
value="Joe" />
<property
name="lastName"
value="Smith" />
</bean>
</beans>
然后在项目 B 中,我添加 A 作为依赖项并具有以下配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean
id="simplePersonAddress01"
parent="simplePersonBase">
<property
name="firstName"
value="BillyBob" />
<property
name="address"
value="1060 W. Addison St" />
<property
name="city"
value="Chicago" />
<property
name="state"
value="IL" />
<property
name="zip"
value="60613" />
</bean>
</beans>
当我像这样使用 ClassPathXmlApplicationContext 时:
BeanFactory beanFactory = new ClassPathXmlApplicationContext( new String[] {
"./*.xml" } );
SimplePerson person = (SimplePerson)beanFactory.getBean( "simplePersonAddress01" );
System.out.println( person.getFirstName() );
Spring 提示它无法解析父 xml。
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'simplePersonBase' is defined
我确信有一种方法可以做到这一点,但是我还没有找到。有谁知道怎么做吗?
最佳答案
尝试使用 classpath*:
前缀。
关于java - 如何在 Maven 依赖项中使用 Spring 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2647099/