SpringBoot切换内置web服务器

SpringBoot内置web服务器切换

SpringBoot的web环境中默认使用tomcat作为内置服务器,其实SpringBoot提供了4中内置服务器供我们选择,我们可以很方便的进行切换。

依赖包下面org.springframework.boot:spring-boot-autoconfigure中下面的web可看到SpringBoot提供了4中内置服务器

在这里插入图片描述

内置服务器切换可通过在pom.xml文件中进行操作如如下所示由Tomcat切换到Jetty:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!--排除tomcat依赖-->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!--引入jetty的依赖-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

启动服务是将显示:
在这里插入图片描述

...... --- [           main] o.s.b.web.embedded.jetty.JettyWebServer  : Jetty started on port(s) 8080 (http/1.1) 

浏览器访问地址:http://localhost:8080/
以此类推可切换其他服务器

猜你喜欢

转载自blog.csdn.net/qingbo_2920249511/article/details/121547889
今日推荐