java - Spring Integration Test Loading Annotated Beans -


for reason, dao not loaded when use @componentscan alone.

my dao:

@repository public class mydao{   @autowire   private datasource ds; } 

my config class (just overrides datasource bean embedded db):

@configuration public class testconfig extends appconfig {      @bean     public datasource getdatasource() throws exception{...} 

my test class:

@runwith(springjunit4classrunner.class) @contextconfiguration(classes = {testconfig.class}) @componentscan public class mydaotest {      @autowired     private mydao target; 

my understanding @componentscan should able find mydao , load (the datasource in testconfig class loaded fine). however, mydao not being loaded. i'm getting "org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.acme.dao.mydao] found dependency." tried specifying packages in @componentscan such com.acme or com.acme.dao.

when include mydao.class 1 of classes in @contextconfiguration, works fine. however, don't want list of classes integration tests...

the following setup load default beans appconfig, while overriding beans specified in testconfig. testconfig can nested class (within mydaotest) long declared static.

@contextconfiguration( classes = testconfig.class ) @runwith(springjunit4classrunner.class) public class mydaotest {     ... }  @import(appconfig.class) public class testconfig {     @bean public datasource getdatasource() throws exception {...} }  @configuration @componentscan( basepackages = {"com.acme"}) public class appconfig {     .... } 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -