2011-08-19 37 views
2

這是解釋here如何結合java & xml配置完成。有用。測試情境框架具有自3.1.0.M2 Java的配置支持:結合Java&xml彈簧配置進行測試

@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配置爲主要配置和負載類似UTIL:性能和東西從XML配置。

我需要做的somwthing這樣的:

@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; 
      } 
     } 
    } 

測試情境框架否則Java的配置支持是沒用的,考慮到有隻能通過XML配置來完成噸的東西。

+0

請記住,Spring 3.1尚未完成。里程碑版本功能不完整,所以如果事情似乎缺失,請不要感到驚訝。 – skaffman

+0

@skaffman:那現在它沒有實現,但它很可能在3.1 RC +中? – lisak

回答

1

springsource blog post報價:

春3.1 RC1我們計劃推出一個 DelegatingSmartContextLoader將委託給候選人 SmartContextLoaders(即,那麼GenericXmlContextLoader和 AnnotationConfigContextLoader)的列表,以確定哪些上下文加載是 適合給定的測試類的配置。獲勝的 候選人將被用於實際加載上下文。一旦這個 工作完成,DelegatingSmartContextLoader將取代 GenericXmlContextLoader作爲默認加載器。請隨時關注JIRA:SPR-8387中的這一發展的進展。