网站链接: element-ui dtcms
当前位置: 首页 > 技术博文  > 技术博文

Spring boot 2.x----------4 web.xml

2021/4/11 6:49:18 人评论

官方文档 :https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-embedded-container 1 使用WebServlet, WebFilter, and WebListener 原生的serlet3.0规范 ServletComponentScan. Scanning for Servlets, …

官方文档 :https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-embedded-container

1 使用@WebServlet, @WebFilter, and @WebListener 原生的serlet3.0规范 + @ServletComponentScan.

Scanning for Servlets, Filters, and listeners
When using an embedded container, automatic registration of classes annotated with @WebServlet, @WebFilter, and @WebListener can be enabled by using @ServletComponentScan.

2 使用RegistrationBean

@Configuration
public class MyRegistConfig {

    @Bean
    public ServletRegistrationBean myServlet(){
        MyServlet myServlet = new MyServlet();

        return new ServletRegistrationBean(myServlet,"/my","/my02");
    }


    @Bean
    public FilterRegistrationBean myFilter(){

        MyFilter myFilter = new MyFilter();
  
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(myFilter);
        filterRegistrationBean.setUrlPatterns(Arrays.asList("/my","/css/*"));
        return filterRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean myListener(){
        MySwervletContextListener mySwervletContextListener = new MySwervletContextListener();
        return new ServletListenerRegistrationBean(mySwervletContextListener);
    }
}


相关资讯

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?