我希望能够让多个网络应用共享一个域项目并在不同的 contextPaths 下运行。
通过在 Spring Boot 应用程序中设置 server.contextPath=/webshop,我不需要为所有 RequestMappings 添加前缀。
我希望网店、管理员和主页共享一个包含所有实体和公共(public)服务的公共(public)域项目。
也许有类似的东西?
public static void main(String[] args) {
new SpringApplicationBuilder(Domain.class)
.showBanner(false)
.child(Admin.class, Webshop.class)
.run(args);
}
我的问题是如何启动具有通用域模型的 Spring Boot 应用程序,然后启动几个具有唯一 contextPaths 的独立 Web 应用程序?
最佳答案
例如这样:
public static void main(String[] args) {
start(Admin.class, Webshop.class).run(args);
start(Another.class).properties("server.port=${other.port:9000}").run(args);
}
private static SpringApplicationBuilder start(Class<?>... sources) {
return new SpringApplicationBuilder(Domain.class)
.showBanner(false)
.child(sources);
}
它将在不同的端口上启动两个应用程序。
关于java - 在一个 Spring Boot 容器中运行多个 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25868218/