简体   繁体   English

Spring Boot - 不覆盖服务器端口属性

[英]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.

相关问题 Spring Boot + Tomcat 忽略 server.port 属性? - Spring Boot + Tomcat ignoring server.port property? 其他应用程序文件中的Spring Boot覆盖属性 - Spring boot overriding property in other application files Spring Boot更改服务器端口 - Spring boot change server port Spring 启动 web 应用程序的 server.port 属性被 ZAEA23489CE3AA9B6406EBB28 上的 Docker 引擎忽略 - The server.port property of a Spring Boot web application is ignored by Docker Engine on Windows Spring 当使用“management.server.port”属性而不是弃用的“management.port”时,启动 MockMvc 测试为执行器端点提供 404 - Spring Boot MockMvc test giving 404 for actuator endpoint when using the "management.server.port" property instead of the deprecated "management.port" 防止覆盖 application.properties 中的某些属性 - Spring Boot - Prevent overriding some property in application.properties - Spring Boot 在 spring 启动测试中使用 wiremock 随机端口设置属性 - Set property with wiremock random port in spring boot test Spring Boot-忽略属性server.contextPath - Spring Boot - ignore property server.contextPath Spring Boot 命令行属性不会覆盖 application.properties 中定义的属性 - Spring Boot command line property not overriding property defined in application.properties Spring 启动应用程序不支持服务器端口的 VM 选项 - Spring boot application not honoring VM options for server port
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM