spring_reference/IX. ‘How-to’ guides/63.3. Use ‘short’ command l...

10 lines
1014 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 63.3. 使用'short'命令行参数
有些人喜欢使用(例如)`--port=9000`代替`--server.port=9000`来设置命令行配置属性。你可以通过在application.properties中使用占位符来启用该功能比如
```java
server.port=${port:8080}
```
**注**:如果你继承自`spring-boot-starter-parent` POM为了防止和Spring-style的占位符产生冲突`maven-resources-plugins`默认的过滤令牌filter token已经从`${*}`变为`@`(即`@maven.token@`代替了`${maven.token}`。如果已经直接启用maven对application.properties的过滤你可能也想使用[其他的分隔符](http://maven.apache.org/plugins/maven-resources-plugin/resources-mojo.html#delimiters)替换默认的过滤令牌。
**注**在这种特殊的情况下端口绑定能够在一个PaaS环境下工作比如Heroku和Cloud Foundry因为在这两个平台中`PORT`环境变量是自动设置的并且Spring能够绑定`Environment`属性的大写同义词。