[英]Spring Boot - not overriding server port property
我有一个Spring Boot项目,无论server.port属性如何,服务器端口总是设置为8080。 除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覆盖。
server.port属性未在我的类路径属性文件中定义,因此在开发环境中默认为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
如果在项目中使用弹簧执行器,默认情况下它指向8080,如果要更改它,则在application.properties中提及management.port = 9001
您还可以尝试使用-Dserver.port =或--server.port =在运行时覆盖端口。 稍后在以java -jar运行时使用。 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.