I'm trying to use Netty server. So I excluded Tomcat in the pom.ml file;
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<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-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
When I run the application, I'm getting the error Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter
Then I add the dependency
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>compile</scope>
</dependency>
Then again when I run the application, I'm getting the error org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
I've checked several questions and no luck yet.
Any ideas?
If you want to use the netty server in WebFlux and WebFlux (spring-boot-starter-webflux) use by default netty server and spring-boot-starter-web use by default tomcat server.
WebFlux provides a choice of servers (Netty, Tomcat, Jetty, Undertow, and Servlet 3.1+ containers). Both Tomcat and Jetty are servlet based servers but Netty and Undertow are non-servlet based servers.
If you want to use netty server and external jar in which using servlet API then you have to add the below dependency in pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.