如何重用我的主要配置但排除了一些..?
像:
@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
答案 0 :(得分:2)
在MyTests
类中,您可以指定要用于配置的类。
@SpringBootTest(classes = {ConfigOne.class, ConfigTwo.class},webEnvironment = WebEnvironment.RANDOM_PORT)
答案 1 :(得分:-1)
尝试使用此
{{1}}