java - Spring profile not properly applied to tests involving @Configurable -


i have weird situation, has happened in several systems already. using spring boot , aspectj ctw @autowired dependencies in entities (instanciated outside container).

the class receives dependencies (an abstract entity) times receive dependency without applying profile (configured @activeprofile in test class). not deterministic, since changing how tests executed different outputs can happen. illustrate situation code:

the entity

@configurable public class abstractmongodocument<t> implements persistable<t> {     @transient     private transient mongotemplate mongotemplate; //entity stuff } 

one of failing tests

@runwith(springjunit4classrunner.class) @springapplicationconfiguration(classes = lovapplication.class) @activeprofiles("local-test") public class mycrazyintegrationtest {      @test     public void filterbyfieldsfullmatchshouldreturnresult() throws exception {         //given         location l1 = new location("name","code",new geojsonpoint(11,10));         l1.save(); //hence need of autowiring there.          //when: whatever         //then: assertions     } } 

there facts find disturbing here:

  1. the dependency injected, some times apparently comes appctx default profile.
  2. if fails 1 test in 1 class, behaves same tests in particular class.
  3. it may or may not happen depending on how execute class (at moment fails if run tests, succeed if run class in isolation, behaves differently in maven).
  4. if debug it, can see dependency injected didn't proper profile. (i discovered injecting applicationcontext , surprisingly discovering different object 1 received in tests).
  5. what worries me most, not sure if situation happen non-test environments example production profile, imply catastrophe.

i have tried open bugs in jira , found nothing, don't discard misconfiguring something. or ideas appreciated.

the behavior experiencing typically should not happen in production deployment; however, is known issue integration test suites load multiple applicationcontexts utilizing @configurable , aspectj load-time weaving.

for details, see following issues in spring's issue tracker:


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

mysql - FireDac error 314 - but DLLs are in program directory -