1、整合filter

springboot-整合filter

方式1
@WebFilter(filtername urlpattern="拦截多个请求,{"*.do","*.action","/firstServlet",}")
public clsss FirstFilter implements Filter{
//重写方法
}
主启动
@ServletComponentScan
@SpringBootApplication



方式2
public class SecondFilter implements Filter{
//重写方法
}
@SpringBootApplication
App2{
@Bean//注册servlet
public ServletRegistrationBean getServletRegistrationBean(){
ServletRegistionBean bean = new ServletRegistrationBean(new SecondServlet())
bean.addUrlMappings("/second")
return bean;
}
@Bean//注册Filter
public ServletRegistrationBean getServletRegistrationBean(){
FilterRegistrationBean bean = new FilterRegistrationBean(new SecondFilter())
bean.addUrlPatterns("/second")
return bean;
}
}

总结:
一个在其实现类中加注解参数实现
一个在其主启动类中用Bean注解+方法实现;

整合listener

<listener>
<listener-class>com.bjsxt.listener.FirstListener</listener-class>
</listener>
@WebListener 不需要加额外的配置
public class FirstListener implements ServletContextListener{
@override
public void contextInitialized(ServletContextEvent e){

}
}
@SpringBoogApplication
@ServletComponentsScan
class App{

}

整合springboot访问静态资源

整合springboot文件上传