使用 SpringBoot,我可以轻松地将相同的应用程序作为具有不同配置的不同实例运行,例如:
@SpringBootApplication
@ComponentScan({"..."})
public class Application {
public static void main(String[] args) {
start(Application.class)
.properties("notification.sender.app.name=SomeApp", "notification.this.app.name =AnotherApp", "server.port=${first.port:9010}").run(args);
start(Application.class)
.properties("first.app.name=AnotherApp", "second.app.name =SomeApp", "server.port=${second.port:9020}").run(args);
}
private static SpringApplicationBuilder start(Class<?>... sources) {
return new SpringApplicationBuilder(sources).bannerMode(Mode.OFF);
}
}
这太棒了,特别是用于测试应用程序间通信的东西。
我现在正在尝试使用 @SpringBootTest 来实现相同的目标,以针对正在运行的应用程序实例运行单元测试。
可能很容易,但我没有。