当前位置 博文首页 > blackball1998的博客:修改servlet配置
通过Spring Boot的配置文件,可以方便地修改servlet配置,下面介绍常用的一些配置
修改端口号,可以使用server.port
配置,默认是8080端口启动
server:
port: 8888
配置完之后就会以指定端口启动
修改项目路径,可以使用server.servlet.context-path
配置,默认是/
server:
servlet:
context-path: /hello
配置了项目路径,要访问项目,就需要在请求中添加项目路径
@RestController
public class MyController {
@RequestMapping("/test")
public String test() {
return "success";
}
}
如发送请求到上面的接口,就需要使用/hello/test这个uri
默认情况下,Spring Boot使用Tomcat作为servlet容器,Spring Boot也支持Jetty和Undertow作为servlet容器,当我们需要时,只需要将默认的Tomcat启动器排除,然后导入需要的容器启动器即可
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
以上示例将项目中的servlet切换成了Undertow