我有一个Spring Boot项目,其中服务器端口始终设置为8080,无论server.port属性如何。除server.port以外的所有属性都正确覆盖。属性配置bean:
@Bean
public PropertySourcesPlaceholderConfigurer properties() {
final PropertySourcesPlaceholderConfigurer poc = new PropertySourcesPlaceholderConfigurer();
poc.setIgnoreResourceNotFound(true);
poc.setIgnoreUnresolvablePlaceholders(true);
final List<Resource> list = new ArrayList<Resource>();
// default (dev) properties
list.add(new ClassPathResource(PROPERTIES_FILE));
// override with -Dproperties.location=C:/path/to/properties/ where overriding application.properties resides
list.add(new FileSystemResource(System.getProperty(EXTERNAL_ARGUMENT_NAME)+PROPERTIES_FILE));
poc.setLocations(list.toArray(new Resource[]{}));
return poc;
}
这意味着我的 classpath application.properties 是默认的(dev 属性),会被 jvm 参数 -Dproperties.location=C:\application\config 覆盖。
在我的 classpath 属性文件中未定义 server.port 属性,因此在 dev 环境中默认为 8080。这很好,但是对于测试,我想指定端口。我的外部属性文件包含此属性:
server.port=10070
日志:
[2016-01-19 11:14:10:010 CET] INFO [restartedMain] support.PropertySourcesPlaceholderConfigurer: Loading properties file from class path resource [application.properties]
[2016-01-19 11:14:10:010 CET] INFO [restartedMain] support.PropertySourcesPlaceholderConfigurer: Loading properties file from file [C:\var\opt\application\config\application.properties]
[2016-01-19 11:14:11:011 CET] INFO [restartedMain] support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$418ca8e8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2016-01-19 11:14:11:011 CET] INFO [restartedMain] tomcat.TomcatEmbeddedServletContainer: Tomcat initialized with port(s): 8080 (http)
[2016-01-19 11:14:11:011 CET] INFO [restartedMain] core.StandardService: Starting service Tomcat