java - 在一个 Spring Boot 容器中运行多个 Web 应用程序

标签 java spring spring-mvc spring-boot

我希望能够让多个网络应用共享一个域项目并在不同的 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/

相关文章:

java - 如何在 Spring MVC 中将 JSON 有效负载发布到 @RequestParam

java - mvn spring-boot :run results in java. lang.LinkageError:违反加载器约束

java.lang.NoSuchMethodError : org. springframework.beans.factory.annotation.AnnotatedBeanDefinition.setRole(I)V

java - Spring:向 websocket 客户端发送消息

Spring Security 通过 URL 进行身份验证

java - 使用ajax和spring mvc上传多个文件

java - ExceptionHandler 调用但不影响 http 响应

java - 游戏设计 - 玩家数据 - 我这样做对吗?

java - 用设计模式替换多个 If\Else

java - eclipse 提示 getSystemCpuLoad 方法在 Java 8 的 OperatingSystemMXBean 中不可用?