在某個博客看到改Jetty的好處,也真是我現在開發的項目後面要用長連接
好處:
<!-- Jetty適合長連接應用,就是聊天類的長連接 -->
<!-- 使用Jetty,需要在spring-boot-starter-web排除spring-boot-starter-tomcat,因爲SpringBoot默認使用tomcat -->
對於配置內置服務器的springBoot,都必定會配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
以上配置springBoot的啓動web服務器,但默認是Tomcat
所以呢,要配置爲jetty要去掉默認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>
並且加上jetty啓動
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
但修改完後就報錯了
Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean
這就鬱悶了,tomcat都能啓動的,聽說改一下服務器就可以的了……
經過搜索,很多都說沒有配置tomcat服務器或者去掉了tomcat(是的,我是去掉了tomcat,但不是找jetty代替了嗎),這麼想着是不是jetty沒有加載進來,直到搜到,感謝博主https://blog.csdn.net/zuofengnihao/article/details/80287249
發現我好像也是這個問題,直接配置spring-boot-starter-jetty默認最新的jetty版本,不兼容我現在用的jdk7,必須手動降版本
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
<jetty.version>9.2.4.v20141103</jetty.version>
</properties>