SpringBoot項目修改訪問端口和訪問路徑的方法
創(chuàng)建SpringBoot項目,啟動后,默認的訪問路徑即主機IP+默認端口號8080:http://localhost:8080/

此時,我們就可以訪問Controller層的接口了,如:http://localhost:8080/hello
package com.springboot.test;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SpringBootTest {
@RequestMapping("/hello")
public String helloSpringBoot() {
return "Hello SpringBoot Project.";
}
}

當然,我們可以通過配置來更改默認端口和項目訪問路徑:
修改端口號
使用properties文件方式:
在src/main/resoutces目錄下創(chuàng)建:application.properties,添加如下配置即可修改端口號:
server.port=8088
使用yml文件方式:
在src/main/resoutces目錄下創(chuàng)建:application.yml,添加如下配置即可修改端口號:
server: port:8088
修改項目訪問路徑
使用properties文件方式:
在application.properties,添加如下配置即可修改項目訪問路徑:
server.context-path=/springboot-demo
使用yml文件方式:
在application.yml,追加如下配置即可修改項目訪問路徑:
server: port:8088 context-path:/springboot-demo
此時,演示properties方式的效果,如下圖:
server.port=8088 server.context-path=/springboot-demo

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Spring Cloud Alibaba整合Sentinel的實現(xiàn)步驟
這篇文章主要介紹了Spring Cloud Alibaba整合Sentinel的實現(xiàn)步驟,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10
Java基于logback?MessageConverter實現(xiàn)日志脫敏方案分析
本文介紹了一種日志脫敏方案,即基于logbackMessageConverter和正則匹配的方法,該方法的優(yōu)點是侵入性低,工作量少,只需修改xml配置文件,適用于老項目,感興趣的朋友跟隨小編一起看看吧2024-10-10
Spring Boot 實現(xiàn)https ssl免密登錄(X.509 pki登錄)
這篇文章主要介紹了Spring Boot 實現(xiàn)https ssl免密登錄(X.509 pki登錄),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-01-01

