Namrata Dayannavar
Namrata Dayannavar

Reputation: 11

Grails Application With SpringBoot using different yml files for different environments

I am using Grails 3.3.1 with spring boot. the build tool is gradle. All application related properties are configured in application.yml file.

Now I want to access different .yml files for different environments [development, test etc]. For this I have created different .yml files per environment. The command used to run server is : grails -Dgrails.env=test run-app Now when i access any property, it gives me the values from application-test.yml file which is as expected.

But when I access server.port, it is reading this property from application.yml instead of application-test.yml.

Can anyone help me in running the application by using server.port from application-test.yml file

The application.yml is as follows:

server: port: 8081

contextPath : /ssp

the application-test.yml is as follows:

server: port: 8443

contextPath : /ssp

I am expecting the server to run on port 8443 as this property is in application-test.yml. But the server runs on port 8081 as mentioned in application.yml

Upvotes: 0

Views: 893

Answers (2)

Ben W.
Ben W.

Reputation: 401

You can override the port directly at startup with --server.port or -Dserver.port

If you want completely different YML, you can set spring.config.location as a parameter. Here's an example:

# start service
/opt/jdk/bin/java \
  -Dserver.port=<your port> \
  -jar /opt/service/<your warfile> --spring.config.location=<your YML>

References: How to configure port for a Spring Boot application

https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-use-short-command-line-argumentsboot-application

Upvotes: 0

Namrata Dayannavar
Namrata Dayannavar

Reputation: 11

I could resolve the above issue by adding server.port per environment in the .yml files

#application.yml:

environments:

development:
    dataSource:
        dbCreate: none
        url: //url
        logSql: true
        username: //username
        password: //password
        driverClassName: "oracle.jdbc.driver.OracleDriver"
        pooled: true
        jmxExport: true
    server:
        port: 8081
        contextPath : /ssp
test:
    dataSource:
        dbCreate: none
        url: //url
        username: //username
        password: //password
        driverClassName: "oracle.jdbc.driver.OracleDriver"
        pooled: true
        jmxExport: true
        logSql: true
    server:
        port: 8082
        contextPath : /ssp

Upvotes: 0

Related Questions