簡體   English   中英

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

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

我的src / test文件夾中有一個spring boot服務器應用程序,該應用程序配置為與test.properties一起運行。

目前,我的屬性如下所示:

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

我想退休server.port並指向我的服務器以從billing.engine.port獲取端口。

是否可以配置Spring來做到這一點?

我的春季應用主班目前看起來像這樣

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);


    }
}

您可以使用此代碼

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

並更改您的application.properties

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

它不是經過測試的代碼。...我是根據我的知識編寫此代碼的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM