Autowire fails after moving spring context to META-INF

832 views Asked by At

After moving my spring context configuration into src/main/resources/META-INF/spring I am not able to wire my beans. Before my spring context was placed directly under the src folder and my tests as well as autowiring runs fine:

enter image description here

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:cmn-dao-context.xml" })
@Transactional
public class ComplaintDaoTest extends TestCase {

    @Autowired
    private ComplaintDao mComplaintDao;

Error:

09.12.2013 23:30:02 org.springframework.test.context.TestContextManager prepareTestInstance
SCHWERWIEGEND: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@873723] to prepare test instance [null(de.bc.qz.dao.ComplaintDaoTest)]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'de.bc.qz.dao.ComplaintDaoTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.bc.qz.dao.ComplaintDao de.bc.qz.dao.ComplaintDaoTest.mComplaintDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [de.bc.qz.dao.ComplaintDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)

database.properties:

<bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>database.properties</value>
    </property>
</bean>

Could somebody help me?

1

There are 1 answers

8
Jean-Philippe Bond On BEST ANSWER

Try with classpath*:META-INF/spring/cmn-dao-context.xml

EDIT

<bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>META-INF/spring/database.properties</value>
    </property>
</bean>