【问题标题】:Set default URL Spring Boot App starts with in deployment设置默认 URL Spring Boot App 在部署中开始
【发布时间】:2021-11-24 07:43:28
【问题描述】:

我有一个使用server.servlet.context-path=/api 在端口 5000 上运行的 Spring Boot 应用程序。

当应用启动时,在我的机器上,我可以在http://localhost:5000/api 访问静态欢迎页面 (index.html) 没问题。

我将此应用程序部署在 Docker 容器中的 AWS CodePipeline 上。问题是,当我在http://my-api-env.eba-uatdpxjr.us-east-2.elasticbeanstalk.com/api 访问我的应用程序的端点时,它工作正常,但我想拥有它,这样我的部署环境的根 url 就不需要手动将/api 添加到末尾访问我的服务。

如何使已部署应用的 URL http://my-api-env.eba-uatdpxjr.us-east-2.elasticbeanstalk.com 自动包含应用的上下文路径 /api 并呈现静态欢迎页面?

Dockerfile

FROM openjdk:8-jdk-alpine
COPY /target/RestApi-0.0.1-SNAPSHOT.jar RestApi-0.0.1-SNAPSHOT.jar
EXPOSE 5000
ENTRYPOINT ["java", "-jar", "/RestApi-0.0.1-SNAPSHOT.jar"]

docker-compose.yml

version: "1.0"
services:
  api_service:
    build: .
    restart: always
    ports:
      - 5000:5000

buildspec.yml

version: 0.2

phases:
  build:
    commands:
      - java -version
      - mvn clean package
artifacts:
  files:
    - 'Dockerfile'
    - target/RestApi-0.0.1-SNAPSHOT.jar

application.properties

# JPA Settings
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create

# Configure Port and Context Path
server.port=5000
server.servlet.context-path=/api

# In the master application.properties file we can control which Spring Profile we want to use
spring.profiles.active=dev

# Set Welcome view to index.html page
spring.mvc.view.suffix = .html

【问题讨论】:

    标签: spring docker rest spring-mvc


    【解决方案1】:

    为什么完全删除上下文路径(默认为 "/")对您不起作用?

    【讨论】:

    • 这对我来说很好,但我想知道是否有办法默认公开上下文路径。
    猜你喜欢
    • 2016-11-03
    • 2022-08-04
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 2015-06-22
    • 2015-05-07
    • 2017-12-10
    • 2019-09-04
    相关资源
    最近更新 更多