2016-12-20 24 views
5

Bazı çekirdeklerin, tüm paketleri taraması gereken <import><import> ürününün bileşen taramasıyla yüklenmesi nasıl hariç tutulur.Test içeriğinden sınıflar hariç tutulması

<context:component-scan base-package="com.main"> 
     <context:exclude-filter expression="com.main.*Controller" type="regex"/> 
</context:component-scan> 

Ama canlı ortamda denetleyicileri gerekir: Bu ana içeriğe koyarsanız nicly çalışır.

Tümleştirme sınama içeriğimden denetleyici sınıfı yüklemesini hariç tutmak istiyorum. Bunu başarmak nasıl mümkün olabilir?

cevap

3

Belirli @ActiveProfile("test")

EDIT'e testinizi

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-2.5.xsd"> 
     <!-- define profile beans at the end of the configuration file --> 
    <beans profile="test"> 
    <context:component-scan base-package="com.main"> 
      <context:exclude-filter expression="com.main.*Controller" type="regex"/> 
    </context:component-scan> 
    </beans> 

    <beans profile="!test"> 
    <context:component-scan base-package="com.main"/> 
    </beans> 

kullanarak ve açıklamalar ekleyerek, ki (referans How to set a Spring profile to a package?) için yaylı profilleri kullanabilirsiniz:

xml bir tanımlamıyorsa <component:scan> etiketi ile, paket taramanızı java konfigürasyonu kullanarak kontrol edebilirsiniz.

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(loader = AnnotationConfigContextLoader.class) 
public class HelperTest { 

    @Configuration 
    @ComponentScan(basePackages = "yourPackage", 
      excludeFilters = @ComponentScan.Filter(value = Controller.class, type = FilterType.ANNOTATION)) 
    @ImportResource(locations = "classpath:context.xml") 
    static class TestConfiguration { 


    } 
+1

Ben ana içeriği değiştirmek istemez şu şekildedir: kontrolörleri daha sonra @ComponentScan ExcludeFilter ile hariç tutulabilir. Mümkünse test bağlamımda neyin hariç tutulacağını söylemek isterim. :) –

+0

Cevabı güncelledim, uygunsa bana bildirin. –

İlgili konular