0

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?

nano_nano
  • 12,351
  • 8
  • 55
  • 83

1 Answers1

3

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>
Jean-Philippe Bond
  • 10,089
  • 3
  • 34
  • 60
  • it fails with the same message if I try: @ContextConfiguration(locations = { "classpath*:META-INF/cmn-dao-context.xml" }) – nano_nano Dec 09 '13 at 23:09
  • also with @ContextConfiguration(locations = { "classpath*:META-INF/spring/cmn-dao-context.xml" }) – nano_nano Dec 09 '13 at 23:11
  • I think I did something wrong by creating the new structure src/main/resources I created those directorys via create new src-directories. META-INF/spring are standard file directories. – nano_nano Dec 09 '13 at 23:14
  • 1
    Put your META-INF in your main src directory – Jean-Philippe Bond Dec 09 '13 at 23:16
  • try with classpath*:META-INF/spring/cmn-dao-context.xml. I did not see that you had the spring folder under META-INF – Jean-Philippe Bond Dec 09 '13 at 23:17
  • thx after putting the directory directly under src it seems to work. unfortunality I get now that exception: Caused by: java.io.FileNotFoundException: class path resource [database.properties] cannot be opened because it does not exist But the database.properties is placed in the same directory... – nano_nano Dec 09 '13 at 23:24
  • Do the same thing with the location property. Check the update. – Jean-Philippe Bond Dec 09 '13 at 23:27
  • yeaaaa. changed it to META-INF/spring/database.properties and works very well! +1 and accepted thx a lot – nano_nano Dec 09 '13 at 23:29