【问题标题】:yml config about http and https关于 http 和 https 的 yml 配置
【发布时间】:2021-11-16 02:37:01
【问题描述】:

application.yml,我需要配置https端口和http端口。

为此,application.properties中的代码如下。

server.port.http=80
server.port.https=443

application.yml,我尝试了以下代码进行配置,
但它不起作用。

代码1

server:
  port: 443
    http: 80

代码2

server:
  port:
    http: 80
  port: 443

如何仅使用application.yml
我可以通过.properties.yml 的合作来做到这一点。
但是,我只想使用 application.yml 来执行此操作。


解决方案

感谢dariosicily的回答,我找到了解决方案。

我配置https和http端口如下。

server:
  port: 443
  ports:
    https: 443
    http: 8080

我需要配置spring boot的默认端口。 因此,我使用server.port=443 配置了默认端口, 以及使用server.ports 的https 和http 端口。

并在java中使用如下。

@Value("${server.ports.http}")
private int serverPortHttp;

@Value("${server.ports.https}")
private int serverPortHttps;

效果很好。谢谢!!!

【问题讨论】:

    标签: spring-boot yaml


    【解决方案1】:

    您可以配置 http 和 https 端口,在您的 application.yml 中使用 httphttps 键创建字典:

    server:
      port: 
          http: 8080
          https: 443
    

    然后您可以访问您的 java 类(或具有等效代码的 kotlin)中的这两个属性:

    @Value("${server.port.http}")
    private int httpPort;
        
    @Value("${server.port.https}")
    private int httpsPort;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多