【发布时间】:2011-08-19 20:55:45
【问题描述】:
解释here如何结合java和xml配置。有用。测试上下文框架从 3.1.0.M2 开始支持 java 配置:
@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;
}
}
}
虽然我不知道如何将 java config 作为主要配置并从 XML 配置中加载诸如 util:properties 之类的东西。
我需要这样做:
@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;
}
}
}
考虑到有很多事情只能通过 XML 配置完成。
【问题讨论】:
-
请记住,Spring 3.1 尚未完成。 Milestone 构建的功能不完整,因此如果似乎缺少某些东西,请不要感到惊讶。
-
@skaffman:所以现在它还没有实现,但很可能会在 3.1 RC+ 中实现?