Spring 4, JUnit 4 without spring boot NoSuchBeanDefinitionException: No qualifying bean of type

350 Views Asked by At

I have a Spring 4.3 application which works fine. I'm trying to use JUnit 4.11 but the context doesn't load.

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'caesb.websupport.service.BatchSolicitacaoService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.inject.Inject()}

base-spring-application.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans>  
  ....
    <tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" />

    <context:annotation-config />

    <context:component-scan base-package="caesb">
    </context:component-scan>
</beans>

test-spring-application.xml

It has only datasource configuration.

BatchSolicitacaoService.java

@Service
public class BatchSolicitacaoService extends BaseEntityService<BatchSolicitacao>
{
...
}

PriorizacaoHidrometroDWService.java

@Service
public class PriorizacaoHidrometroDWService extends BaseEntityService<PriorizacaoHidrometroDW>
{
...
   @Inject 
   private BatchSolicitacaoService batchSolicitacaoService;

}

BasicTest.java

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class})
@ContextConfiguration({"classpath*:/base-spring-application.xml","classpath*:/test-spring-application.xml"})
@Transactional
public class BasicTest
{
    @Test
    public void test() {
        System.out.println("teste teste");
    }
}

I have added @TestExecutionListeners, but without success. I removed @Transaction, but also without success.

0

There are 0 best solutions below