亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring Boot 在 application.properties 中重命名

Spring Boot 在 application.properties 中重命名

富國滬深 2023-06-04 11:24:28
我的 src/test 文件夾中有一個 spring boot 服務器應用程序,該應用程序配置為與我的 test.properties 一起運行。目前我的屬性是這樣的:server.port=9119server.ssl.enabled=falselogging.config=classpath:logback-spring.xmllogging.file=messageslogging.file.max-size=50MBlogging.level.com.nulogix=DEBUGbilling.engine.address=127.0.0.1billing.engine.port=9119billing.engine.api.version=0.97billing.engine.core.version=0.97billing.engine.core.name=Patient_Responsibility我想停用 server.port 并指向我的服務器以從 billing.engine.port 獲取端口。是否可以配置 Spring 來執行此操作?我的 spring 應用程序主類目前看起來像這樣import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;@SpringBootApplicationpublic 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);    }}
查看完整描述

1 回答

?
慕桂英4014372

TA貢獻1871條經驗 獲得超13個贊

你可以使用這個代碼


@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

這不是經過測試的代碼....我正在根據我的知識編寫這段代碼


查看完整回答
反對 回復 2023-06-04
  • 1 回答
  • 0 關注
  • 264 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號