如何重用我的配置并在SpringBoot Test中排除另一个配置?

时间:2016-11-16 19:28:48

标签: spring-boot spring-test

如何重用我的主要配置但排除了一些..?

像:

@SpringBootApplication
@EnableAutoConfiguration
public class Application {

    public static void main(String[] args) {
        new SpringApplicationBuilder(Application.class, 
                ConfigOne.class,
                ConfigTwo.class,
                ConfigThree.class //I want to exclude the ConfigThree in my tests and use my own ConfigThreeTest.class
                ).run(args);
    }
}
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class MyTests {

    //test...
}
@Configuration
public class ConfigThreeTest {

    //config...

}

在上面的示例中,我想要排除ConfigThree.class并使用ConfigThreeTest.class

2 个答案:

答案 0 :(得分:2)

MyTests类中,您可以指定要用于配置的类。

@SpringBootTest(classes = {ConfigOne.class, ConfigTwo.class},webEnvironment = WebEnvironment.RANDOM_PORT)

答案 1 :(得分:-1)

尝试使用此

{{1}}