yml config about http and https

Viewed 217

In application.yml, I need to config https port and http port.

For this, code is as follows in application.properties.

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

In application.yml, I tried follwing code for configuration,
but it doesn't work.

code1

server:
  port: 443
    http: 80

code2

server:
  port:
    http: 80
  port: 443

How do this only with application.yml?
I can do it with collaboration of .properties and .yml.
However, I want to do this with only application.yml.


Solution

I found solution thanks to answer of dariosicily.

I configured https and http port as follows.

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

I need to configure default port of spring boot. So, I configured default port using server.port=443, and https and http port using server.ports.

And used them in java as follows.

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

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

It works really well. Thank you!!!

1 Answers

You can configure both http and https ports creating a dictionary with http and https keys in your application.yml :

server:
  port: 
      http: 8080
      https: 443

Then you can access both properties in your java class (or kotlin with an equivalent code) :

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