grails - 使用SpringBoot的Grails应用程序针对不同的环境使用不同的yml文件

标签 grails spring-boot gradle yaml

我在Spring Boot中使用Grails 3.3.1。构建工具是gradle。
所有与应用程序相关的属性都在application.yml文件中配置。

现在,我想为不同的环境(开发,测试等)访问不同的.yml文件。为此,我为每个环境创建了不同的.yml文件。
用于运行服务器的命令是:grails -Dgrails.env = test run-app
现在,当我访问任何属性时,它将按预期提供给我来自application-test.yml文件的值。

但是,当我访问server.port时,它是从application.yml而不是application-test.yml读取此属性。

任何人都可以通过application-test.yml文件中的server.port帮助我运行应用程序

application.yml如下:

服务器:
端口:8081

contextPath:/ ssp

application-test.yml如下:

服务器:
端口:8443

contextPath:/ ssp

我期望服务器在端口8443上运行,因为此属性位于application-test.yml中。但是,服务器在application.yml中提到的端口8081上运行

最佳答案

我可以通过在.yml文件中按环境添加server.port来解决上述问题

#application.yml:

环境:

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

关于grails - 使用SpringBoot的Grails应用程序针对不同的环境使用不同的yml文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47300675/

相关文章:

java - 由于服务类错误,Spring Boot 应用程序未启动

json - 可以在 Grails 1.3.7 中漂亮地打印 JSON 吗?

grails - Grails 3.2.8无法在 Controller 中获取springSecurityService.currentUser

java - 如何在Spring Boot中将父项目的gradle属性传递给logback.xml?

spring-boot - Spring + Lombok + @SneakyThrows

android - versionCode 总是被覆盖为 -1

android - 从 'com.android.tools.build:gradle:2.3.3'转换为3.0.1后,无法将索引1的值转换为维度:type = 0x1d

gradle - variantOutput.getPackageApplication()已过时

grails - Grails约束何时起作用?

grails - 如何在BootStrap.groovy init中创建具有多个关系的对象