last day (16 days later) » 

5:55 PM
1
A: What is the difference between grouping config via @import and @ContextConfiguration.?

Sam BrannenIf you follow approach #1, both interceptors are actually being loaded... just in different ApplicationContexts. @ContextHierarchy instructs the Spring TestContext Framework to load a hierarchy of contexts. Thus, the two configuration setups you have are not identical with regard to contexts....

 
Thank you Sam. But if you say java config in my class knows both config in XML and Java, then why xml interceptor didn't work when i invoke. hello.sayHello("Manoj"). Context loaded from Java config should have both XML configuration and Java configuration correct?
 
With the current code in your repository you are not creating a context hierarchy, so the XML interceptor does intercept the "Manoj" message: @Test public void test() { hello.sayHello("Manoj"); xmlSer.sayHello("Jeeva"); } outputs XML Intecepted Manoj / DSL InterceptedManoj / XML Intecepted Jeeva / Hello Jeeva / DSL InterceptedJeeva.
If you follow approach #1 -- as I mentioned before -- you are in fact creating two contexts, and the XML interceptor cannot see flows in the child context.
 
So, just by defining configuration inside @contextheirarchy, we cannot expect that it will all load in a single context. We need to import one config into another. What might be the purpose i need multiple context in my application?
 
Exactly. The whole point of @ContextHierarchy is to load multiple contexts and configure them in a hierarchy of parent-child contexts. See the Context hierarchies section of the reference manual for details. Typical use cases for hierarchies are also outlined in the reference manual.
You might also find the Mixing XML, Groovy scripts, and annotated classes section of the reference manual enlightening.
If you are satisfied with my answer, I would appreciate it if you would accept it. ;)
 
One more doubt i have, If you see in my updated question section above, I am loading the interceptor configuration in new applicationContext. I could access the wiretap as bean in my child context, but I couldn't use the @GlobalInterceptor in my chid context. So child context inherit only beans from parent? Github files in the same project: /Sample1/src/main/java/com/config/DSLInterceptor.java /Sample1/src/main/java/com/config/SpringConfiguration.java /Sample1/src/test/java/com/sample/SampleTest.java
 
6:41 PM
That's basically correct... except that contexts do not "inherit" beans. Beans in a child context can see or reference beans in a parent context, but not the other way. Beans in a parent context cannot see or reference beans in a child context.
The notion context hierarchies is a core Spring concept. This is not special to testing.
 
 
2 hours later…
8:35 PM
Sorry, In my example, SpringConfiguration.java is loaded as child context. DSLInterceptor.java is loaded as parent context.
Child context is seeing beans from parent context. But child context is not taking the @GlobalInterceptor which is configured in the parent context.
wiretap is a bean in parent context annotated with @GlobalInterceptor. I auto wired the wiretap in child and printed the hash code. But whatever the functionality this wiretap supposed to do because of @GlobalInterceptor is not working. See my point..?
 

  last day (16 days later) »