springboot初步整合web(一)
原创
©著作权归作者所有:来自51CTO博客作者wx637f0ba1ddc42的原创作品,请联系作者获取转载授权,否则将追究法律责任
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文件上传