常见问题总结

注册Listener和Filter

SpringBoot工程支持使用Servlet3注解,可直接自动注册监听器和过滤器,但是我们必须配置启用Servlet注解扫描,这需要在启动类上添加@ServletComponentScan注解,然后我们定义的Listener或Filter使用对应的Servlet注解标注即可使用了。

将Servlet容器改为Undertow

SpringBoot默认使用Tomcat作为Servlet容器,Tomcat性能不错且功能强大、代码健壮性良好,但Undertow源码更轻量,性能跑分比Tomcat还要好一些。如果想将容器改为Undertow,首先要排除spring-boot-starter-web包中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>

然后加入Undertow的起步依赖。

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
作者:Gacfox
版权声明:本网站为非盈利性质,文章如非特殊说明均为原创,版权遵循知识共享协议CC BY-NC-ND 4.0进行授权,转载必须署名,禁止用于商业目的或演绎修改后转载。