jeudi 19 avril 2018

Test application cannot find autowired bean in same project

I have a jar file that is the persistence layer, ad I just want to test the DAO that are simply autowired into other service layer clasees. But I want to test without any mocking or whatever.

I think this should be pretty simple. I have this in my srs/test/java

@RunWith(SpringRunner.class)
@ComponentScan("com.xxxx")
public class ApplicationTester  {

@Autowired 
AplicationDocumentDao aplicationDocumentDao;

@Test
private void testAplicationDocumentDao() {
    aplicationDocumentDao.allForOrg(1);
}

}

All the DAO's are in the same projust under the usual /src/main/java

When I run the mvn to just run the tests like this:

  mvn -Dtest=ApplicationTester test

I get this error:

 Error creating bean with name 'xxx.test.ApplicationTester': Unsatisfied dependency expressed through field 'aplicationDocumentDao'; 
 nested exception is 0rg.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'xxx.dao.AplicationDocumentDao' available: 
 expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Which means is can't find the Bean of course, but i would think the @ComponentScan would pick up add the Dao's.

How do I get this tester to find all my Dao's (Which are all annotated with @Componenet) and are picked up just fine in the rest for the application.

Any ideas?

Aucun commentaire:

Enregistrer un commentaire