最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot替換默認(rèn)的tomcat服務(wù)器的方法

 更新時(shí)間:2024年08月13日 08:25:36   作者:HBLOG  
Tomcat是Apache基金下的一個(gè)輕量級的Servlet容器,支持Servlet和JSP,Tomcat具有Web服務(wù)器特有的功能,在SpringBoot框架中,我們使用最多的是Tomcat,這是SpringBoot默認(rèn)的容器技術(shù),本文給大家介紹了Spring?Boot如何替換默認(rèn)的tomcat服務(wù)器,需要的朋友可以參考下

1.為什么要替換默認(rèn)tomcat?

Tomcat是Apache基金下的一個(gè)輕量級的Servlet容器,支持Servlet和JSP。Tomcat具有Web服務(wù)器特有的功能,包括 Tomcat管理和控制平臺(tái)、安全管理和Tomcat閥等。Tomcat本身包含了HTTP服務(wù)器,因此也可以視作單獨(dú)的Web服務(wù)器。在SpringBoot框架中,我們使用最多的是Tomcat,這是SpringBoot默認(rèn)的容器技術(shù),而且是內(nèi)嵌式的Tomcat。

Tomcat與Undertow的優(yōu)劣對比

Undertow是Red Hat公司的開源產(chǎn)品, 它完全采用Java語言開發(fā),是一款靈活的高性能Web服務(wù)器,支持阻塞IO和非阻塞IO。由于Undertow采用Java語言開發(fā),可以直接嵌入到Java項(xiàng)目中使用。同時(shí), Undertow完全支持Servlet和Web Socket,在高并發(fā)情況下表現(xiàn)非常出色。

我們在相同機(jī)器配置下壓測Tomcat和Undertow,得到的測試結(jié)果如下所示:

QPS測試結(jié)果對比:

Tomcat

Undertow

通過測試發(fā)現(xiàn),在高并發(fā)系統(tǒng)中,Tomcat相對來說比較弱。在相同的機(jī)器配置下,模擬相等的請求數(shù),Undertow在性能和內(nèi)存使用方面都是最優(yōu)的。并且Undertow新版本默認(rèn)使用持久連接,這將會(huì)進(jìn)一步提高它的并發(fā)吞吐能力。所以,如果是高并發(fā)的業(yè)務(wù)系統(tǒng),Undertow是最佳選擇。

2.代碼工程

實(shí)驗(yàn)?zāi)繕?biāo)

用undertow替換默認(rèn)的tomcat

pom.xml

先排除tomcat,然后添加undertow依賴包

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>springboot-demo</artifactId>
        <groupId>com.et</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>Undertow</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                    <groupId>org.springframework.boot</groupId>
                </exclusion>
            </exclusions>

        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>
        <!--jetty-->
        <!--
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>-->
    </dependencies>
</project>

controller

package com.et.undertow.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class HelloWorldController {
    @RequestMapping("/hello")
    public Map<String, Object> showHelloWorld(){
        Map<String, Object> map = new HashMap<>();
        map.put("msg", "HelloWorld");
        return map;
    }
}

DemoApplication.java

package com.et.undertow;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

   public static void main(String[] args) {
      SpringApplication.run(DemoApplication.class, args);
   }
}

代碼倉庫

3.測試

啟動(dòng)Spring Boot應(yīng)用,控制臺(tái)日志發(fā)現(xiàn)已經(jīng)使用undertow了

 . ____ _ __ _ _
 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/ ___)| |_)| | | | | || (_| | ) ) ) )
 ' |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot :: (v2.2.5.RELEASE)

2024-08-12 13:40:21.429 INFO 34216 --- [ main] com.et.undertow.DemoApplication : Starting DemoApplication on BJDPLHHUAPC with PID 34216 (D:\IdeaProjects\ETFramework\Undertow\target\classes started by Dell in D:\IdeaProjects\ETFramework)
2024-08-12 13:40:21.433 INFO 34216 --- [ main] com.et.undertow.DemoApplication : No active profile set, falling back to default profiles: default
2024-08-12 13:40:22.663 WARN 34216 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2024-08-12 13:40:22.684 INFO 34216 --- [ main] io.undertow.servlet : Initializing Spring embedded WebApplicationContext
2024-08-12 13:40:22.684 INFO 34216 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1196 ms
2024-08-12 13:40:22.827 INFO 34216 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2024-08-12 13:40:22.947 INFO 34216 --- [ main] io.undertow : starting server: Undertow - 2.0.29.Final
2024-08-12 13:40:22.956 INFO 34216 --- [ main] org.xnio : XNIO version 3.3.8.Final
2024-08-12 13:40:22.966 INFO 34216 --- [ main] org.xnio.nio : XNIO NIO Implementation Version 3.3.8.Final
2024-08-12 13:40:23.065 INFO 34216 --- [ main] o.s.b.w.e.u.UndertowServletWebServer : Undertow started on port(s) 8088 (http) with context path ''
2024-08-12 13:40:23.067 INFO 34216 --- [ main] com.et.undertow.DemoApplication : Started DemoApplication in 2.021 seconds (JVM running for 2.409)

到此這篇關(guān)于SpringBoot替換默認(rèn)的tomcat服務(wù)器的方法的文章就介紹到這了,更多相關(guān)SpringBoot替換tomcat內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • IDEA中Maven依賴包下載不了的問題解決方案匯總

    IDEA中Maven依賴包下載不了的問題解決方案匯總

    這篇文章主要介紹了IDEA中Maven依賴包下載不了的問題解決方案匯總,文中通過圖文示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • 使用Spring的攔截器監(jiān)測每個(gè)Controller或方法的執(zhí)行時(shí)長

    使用Spring的攔截器監(jiān)測每個(gè)Controller或方法的執(zhí)行時(shí)長

    這篇文章主要介紹了使用Spring的攔截器監(jiān)測每個(gè)Controller或方法的執(zhí)行時(shí)長,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • Java中生成不重復(fù)隨機(jī)數(shù)的四種方法舉例詳解

    Java中生成不重復(fù)隨機(jī)數(shù)的四種方法舉例詳解

    在Java編程中獲取隨機(jī)數(shù)是常見的需求,這篇文章主要介紹了Java中生成不重復(fù)隨機(jī)數(shù)的四種方法,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-04-04
  • linux部署springBoot項(xiàng)目的腳本問題

    linux部署springBoot項(xiàng)目的腳本問題

    這篇文章主要介紹了linux部署springBoot項(xiàng)目的腳本問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-05-05
  • Spring Cloud Feign統(tǒng)一設(shè)置驗(yàn)證token實(shí)現(xiàn)方法解析

    Spring Cloud Feign統(tǒng)一設(shè)置驗(yàn)證token實(shí)現(xiàn)方法解析

    這篇文章主要介紹了Spring Cloud Feign統(tǒng)一設(shè)置驗(yàn)證token實(shí)現(xiàn)方法解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • java中添加按鈕并添加響應(yīng)事件的方法(推薦)

    java中添加按鈕并添加響應(yīng)事件的方法(推薦)

    下面小編就為大家?guī)硪黄猨ava中添加按鈕并添加響應(yīng)事件的方法(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-04-04
  • SpringBoot中的跨域詳解

    SpringBoot中的跨域詳解

    這篇文章主要介紹了SpringBoot中的跨域詳解,在瀏覽器上當(dāng)前訪問的網(wǎng)站,向另一個(gè)網(wǎng)站發(fā)送請求,用于獲取數(shù)據(jù)的過程就是跨域請求,跨域是瀏覽器的同源策略決定的,是一個(gè)重要的瀏覽器安全策略,需要的朋友可以參考下
    2023-08-08
  • Spring數(shù)據(jù)訪問模板化方法

    Spring數(shù)據(jù)訪問模板化方法

    今天小編就為大家分享一篇關(guān)于Spring數(shù)據(jù)訪問模板化,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • 簡單介紹Java編程中的線程池

    簡單介紹Java編程中的線程池

    這篇文章主要介紹了Java編程中的線程池,進(jìn)程和線程的并發(fā)是Java編程中的重要環(huán)節(jié),需要的朋友可以參考下
    2015-09-09
  • springboot配置mybatis和事務(wù)管理方式

    springboot配置mybatis和事務(wù)管理方式

    這篇文章主要介紹了springboot配置mybatis和事務(wù)管理方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04

最新評論

武城县| 望江县| 太康县| 禹城市| 巴彦淖尔市| 廊坊市| 梧州市| 井陉县| 郸城县| 株洲市| 安仁县| 古浪县| 正蓝旗| 汽车| 将乐县| 于都县| 乌兰察布市| 厦门市| 德兴市| 临湘市| 启东市| 前郭尔| 筠连县| 峡江县| 临夏县| 高唐县| 阿瓦提县| 苗栗市| 陇西县| 兖州市| 行唐县| 伊川县| 威宁| 宜春市| 会宁县| 澄江县| 义乌市| 沁水县| 万载县| 西畴县| 濮阳市|