[英]Spring Boot - not overriding server port property
I've got a Spring Boot project where the server port always gets set to 8080, regardless of the server.port property. 我有一个Spring Boot项目,无论server.port属性如何,服务器端口总是设置为8080。 All properties except server.port gets overridden correctly.
除server.port之外的所有属性都会被正确覆盖。 Property configuration bean:
属性配置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;
}
This means my classpath application.properties is the default (dev properties), which get overridden by jvm argument -Dproperties.location=C:\\application\\config. 这意味着我的classpath application.properties是默认的(dev属性),它被jvm参数-Dproperties.location = C:\\ application \\ config覆盖。
The server.port property is not defined in my classpath properties file, so it defaults to 8080 in dev environment. server.port属性未在我的类路径属性文件中定义,因此在开发环境中默认为8080。 This is fine, but for test I would like to specify the port.
这很好,但是为了测试我想指定端口。 My external properties file contains this property:
我的外部属性文件包含以下属性:
server.port=10070
Logs: 日志:
[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
You can also try overriding the port at runtime with -Dserver.port= or --server.port=. 您还可以尝试使用-Dserver.port =或--server.port =在运行时覆盖端口。 Use later when you are running as java -jar.
稍后在以java -jar运行时使用。 Hope this helps.
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.