How to use a Spring config file in a Maven dependency

Posted by javamonkey79 on Stack Overflow See other posts from Stack Overflow or by javamonkey79
Published on 2010-04-15T16:21:53Z Indexed on 2010/04/15 16:23 UTC
Read the original article Hit count: 399

Filed under:
|
|
|

In dependency A I have the following:

<beans>
    <bean
        id="simplePersonBase"
        class="com.paml.test.SimplePerson"
        abstract="true">
        <property
            name="firstName"
            value="Joe" />
        <property
            name="lastName"
            value="Smith" />
    </bean>
</beans>

And then in project B, I add A as a dependency and have the following config:

<?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>

When I use ClassPathXmlApplicationContext like so:

    BeanFactory beanFactory = new ClassPathXmlApplicationContext( new String[] {
        "./*.xml" } );

    SimplePerson person = (SimplePerson)beanFactory.getBean( "simplePersonAddress01" );
    System.out.println( person.getFirstName() );

Spring complains as it can not resolve the parent xml.

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'simplePersonBase' is defined

I am sure there is a way to do this, however, I have not found it. Does anyone know how?

© Stack Overflow or respective owner

Related posts about spring

Related posts about maven