简体   繁体   English

Spring Boot重命名application.properties中的server.port

[英]Spring Boot renaming server.port in application.properties

I have a spring boot server app in my src/test folder that is configured to run with my test.properties. 我的src / test文件夹中有一个spring boot服务器应用程序,该应用程序配置为与test.properties一起运行。

Currently my properties looks like this: 目前,我的属性如下所示:

server.port=9119
server.ssl.enabled=false
logging.config=classpath:logback-spring.xml
logging.file=messages
logging.file.max-size=50MB
logging.level.com.nulogix=DEBUG
billing.engine.address=127.0.0.1
billing.engine.port=9119
billing.engine.api.version=0.97
billing.engine.core.version=0.97
billing.engine.core.name=Patient_Responsibility

I want to retire server.port and point my server to get the port from billing.engine.port. 我想退休server.port并指向我的服务器以从billing.engine.port获取端口。

Is it possible to configure Spring to do this? 是否可以配置Spring来做到这一点?

My spring app main class currently looks like this 我的春季应用主班目前看起来像这样

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
public class MockServerApp {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new SpringApplicationBuilder(MockServerApp.class)       
        .properties("spring.config.name:test")
        .build()
        .run(args);


    }
}

you can use this code 您可以使用此代码

@Component
public class ServerPortCustomizer 
  implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
    @Value("${billing.engine.port}")
    private String SERVERPORTNO;
    @Override
    public void customize(ConfigurableWebServerFactory factory) {
        factory.setPort(SERVERPORTNO);
    }
}

and also change your application.properties 并更改您的application.properties

#server.port=9119
billing.engine.port=9119

it's not a tested code.... I am writing this code based on my knowledge 它不是经过测试的代码。...我是根据我的知识编写此代码的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM