It is explained here how combining java & xml configuration开发者_如何学Python is done. It works. Test Context framework has java config support since 3.1.0.M2 :
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
public class LangDetectorTest extends AbstractTestNGSpringContextTests {
@Configuration
static class ContextConfiguration {
@Bean
public LangDetector langDetector() throws SystemException {
LangDetector orderService = new LangDetector();
return orderService;
}
}
}
Though I can't figure out how to have java config as the main configuration and load something like util:properties and stuff from XML configuration.
I'd need to do somwthing like this:
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
@ImportResource("classpath:context/LangDetectorTest-test.xml")
public class LangDetectorTest extends AbstractTestNGSpringContextTests {
@Configuration
static class ContextConfiguration {
@Bean
public LangDetector langDetector() throws SystemException {
LangDetector orderService = new LangDetector();
return orderService;
}
}
}
Otherwise java config support for Test Context framework is useless, considering that there are tons of things that can be done only via XML configuration.
Quoting from springsource blog post :
For Spring 3.1 RC1 we plan to introduce a DelegatingSmartContextLoader that will delegate to a list of candidate SmartContextLoaders (i.e., GenericXmlContextLoader and AnnotationConfigContextLoader) to determine which context loader is appropriate for a given test class's configuration. The winning candidate will then be used to actually load the context. Once this work is complete, DelegatingSmartContextLoader will replace GenericXmlContextLoader as the default loader. Feel free to follow the progress of this development in JIRA: SPR-8387.
精彩评论