【问题标题】:Combining Java & xml spring configuration for testing结合Java & xml spring 配置进行测试
【发布时间】: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+ 中实现?

标签: java spring testing


【解决方案1】:

引用springsource blog post

对于 Spring 3.1 RC1,我们计划引入一个 DelegatingSmartContextLoader 将委托给候选人列表 SmartContextLoaders(即 GenericXmlContextLoader 和 AnnotationConfigContextLoader) 来确定哪个上下文加载器是 适用于给定测试类的配置。获胜的 然后候选人将用于实际加载上下文。一旦这 工作完成,DelegatingSmartContextLoader 将替换 GenericXmlContextLoader 作为默认加载器。随时关注 JIRA 的开发进展:SPR-8387。

【讨论】:

    猜你喜欢
    • 2016-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-31
    • 2014-01-25
    • 2013-10-24
    • 2013-10-22
    • 2023-03-21
    相关资源
    最近更新 更多