项目位于Groovy / Grails / Gradle / Camel route
这似乎很合理:
server:
port: ${PORT}
但是我得到:
java.lang.NumberFormatException: For input string: "${PORT}"
at org.grails.config.CodeGenConfig.convertToType(CodeGenConfig.groovy:191)
at org.grails.config.CodeGenConfig.getProperty(CodeGenConfig.groovy:264)
at grails.config.ConfigMap$getProperty.call(Unknown Source)
at run-app.run(run-app.groovy:31)
at org.grails.cli.profile.commands.script.GroovyScriptCommand.handle(GroovyScriptCommand.groovy:152)
at org.grails.cli.profile.AbstractProfile.handleCommand(AbstractProfile.groovy:452)
at org.grails.cli.GrailsCli.handleCommand(GrailsCli.groovy:373)
at org.grails.cli.GrailsCli$_handleCommandWithCancellationSupport_closure6.doCall(GrailsCli.groovy:464)
at org.grails.cli.GrailsCli$_handleCommandWithCancellationSupport_closure6.call(GrailsCli.groovy)
字符串env vars没有问题,可以正常工作。
搜索时,找不到任何语法强制转换为int。
有什么想法吗?
最佳答案
在Grails / Spring Boot应用程序中,如果配置简写如下,则:
server:
port: ${PORT}
那么应用程序希望在应用程序启动时将
--PORT=8090
(例如)作为系统arg /环境属性提供。确保提供了环境变量。为了使环境变量值在
application.yml
中可用,我们还需要在Grails应用程序中进行以下任务配置:bootRun {
systemProperties = System.properties
}
使用普通 Vanilla Spring Boot Maven应用程序不是必需的。
此外,为避免任何形式的异常,我们还可以在可行的情况下为port提供默认值,如下所示:
server:
port: ${PORT:8085}
关于grails - YAML-groovy-env var不能为整数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41729146/