gpt4 book ai didi

java - 结合Java和xml spring配置进行测试

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:15:48 30 4
gpt4 key购买 nike

说明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 配置作为主要配置并从 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 配置才能完成,因此对 Test Context 框架的 java 配置支持是无用的。

最佳答案

引自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.

关于java - 结合Java和xml spring配置进行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7127310/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com