我可以假定下面的YML格式不再适用于DW 0.7.0了吗? (使用@ char插入env var)
server: applicationConnectors: - type: http bindHost: @OPENSHIFT_DIY_IP@ port: @OPENSHIFT_DIY_PORT@
错误:
Malformed YAML at line: 28,column: 17; while scanning for the next token; found character @ ‘@’ that cannot start any token. (Do not use @ for indentation); in ‘reader’,line 28,column 17:
bindHost: @OPENSHIFT_DIY_IP@
所以我决定使用这种格式:
server: type: simple applicationContextPath: / adminContextPath: /admin connector: type: http bindHost: localhost port: 8080
并试图通过jvm选项覆盖它:
java -Ddw.server.connector.bindHost=$OPENSHIFT_DIY_IP -Ddw.server.connector.port=$OPENSHIFT_DIY_PORT -jar target/myapp.jar server myapp.yml
我的本地env变量:
OPENSHIFT_DIY_IP=localhost OPENSHIFT_DIY_PORT=8080
我从这个设置得到的错误:
Exception in thread “main” java.lang.RuntimeException: java.net.SocketException: Unresolved address
at org.eclipse.jetty.setuid.SetUIDListener.lifeCycleStarting(SetUIDListener.java:213)
…
Caused by: java.net.SocketException: Unresolved address
at sun.nio.ch.Net.translateToSocketException(Net.java:157)
…
WARN [2014-05-03 20:11:19,412] org.eclipse.jetty.util.component.AbstractLifeCycle: Failed org.eclipse.jetty.server.Server@91b85: java.lang.RuntimeException: java.net.SocketException: Unresolved address
我究竟做错了什么?
解决方法
See the docs here.
例
// put environment variable inside ${} // use :- operator to provide default value dbHost: ${DB_HOST} dbPort: ${DB_PORT:-1234} // dbPort = 1234,if DB_PORT environment variable has no value
重要注意事项:为了使其工作,您需要使用EnvironmentVariableSubstitutor设置一个SubstituingSourceProvider.
// Enable variable substitution with environment variables bootstrap.setConfigurationSourceProvider( new SubstitutingSourceProvider( bootstrap.getConfigurationSourceProvider(),new EnvironmentVariableSubstitutor()) );