0

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.

  • I believe your Spring context is not constructed as expected. Can you try using @ContextConfiguration(classes = YourMainClass.class) just to test? – hovanessyan Feb 15 '19 at 19:17
  • what is the classpath* for ? put directly the name of your config file (if it is in your resources folder of course) : @ContextConfiguration({"classpath:base-spring-application.xml","classpath:test-spring-application.xml"}) – sam3131 Feb 15 '19 at 20:12
  • I do not know if I made it clear, but the application run normally with these settings. This problem only happens in unit tests. – Wagner Santos Feb 18 '19 at 12:02

0 Answers0