软件编程
位置:首页>> 软件编程>> java编程>> SpringBoot项目修改访问端口和访问路径的方法

SpringBoot项目修改访问端口和访问路径的方法

作者:Kevin_PB  发布时间:2023-07-13 11:23:35 

标签:SpringBoot,访问端口,访问路径

创建SpringBoot项目,启动后,默认的访问路径即主机IP+默认端口号8080:http://localhost:8080/

SpringBoot项目修改访问端口和访问路径的方法

此时,我们就可以访问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.";
}
}

SpringBoot项目修改访问端口和访问路径的方法

当然,我们可以通过配置来更改默认端口和项目访问路径:

修改端口号

使用properties文件方式:

在src/main/resoutces目录下创建:application.properties,添加如下配置即可修改端口号:


server.port=8088

使用yml文件方式:

在src/main/resoutces目录下创建: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

SpringBoot项目修改访问端口和访问路径的方法

来源:https://blog.csdn.net/qq_40087415/article/details/82497668

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com