Spring boot設置啟動監聽端口


一、通過配置

修改application.properties

在屬性文件中添加server.port=8000

 

二、直接看代碼:

 1 @Controller
 2 @EnableAutoConfiguration
 3 @ComponentScan
 4 public class CallMain extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {
 5     private final static Logger logger = LoggerFactory.getLogger(CallMain.class);
 6 
 7     public static void main(String[] args) throws Exception {
 8 
 9                 //...    
10         SpringApplication.run(CallMain.class, args);
11         logger.debug("spring boot system init successfully...");
12     }
13 
14     @Override
15     public void customize(ConfigurableEmbeddedServletContainer container) {
16         container.setPort(8000);
17         
18     }
19 }        

三、關鍵點

1. 啟動類要繼承SpringBootServletInitializer類。

2. 啟動類要實現EmbeddedServletContainerCustomizer接口。

3. 通過復寫customize方法實現端口的設置。

4. 這個接口在2.0.x版本中刪除了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM