SpringBoot中Server配置

1.Spring Boot中内嵌了TomcatJettyUndertow服务器。
默认情况下,内嵌的服务器HTTP请求监听8080端口
2.Spring Boot默认servlet容器为tomcat

一、配置Tomcat
1.配置端口号

Spring Boot 默认端口是8080,如果想要进行更改的话,在配置文件中
加入:

server.port=8081
2.配置context-path
server.servlet.context-path=/spring-boot

访问地址:
http://ip:port/spring-boot

3.配置session的超时时间
server.servlet.session.timeout=2M
二、替换Tomcat

如果要使用Jetty或者Undertow为Servlet容器,只需修改spring-boot-starter-web依赖

2.使用Jetty servlet容器

在pom.xml中,将spring-boot-starter-web的依赖由spring-boot-start
er-tomcat替换为spring-boot-starter-jetty

<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-jetty</artifactId>
</dependency>
2.使用Undertow servlet容器

在pom.xml中,将spring-boot-starter-web的依赖由spring-boot-start
er-tomcat替换为spring-boot-starter-undertow

<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>

此时需要将tomcat-embed-jasper注释掉

<!--        <dependency>-->
<!--            <groupId>org.apache.tomcat.embed</groupId>-->
<!--            <artifactId>tomcat-embed-jasper</artifactId>-->
<!--            <scope>provided</scope>-->
<!--        </dependency>-->
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值