方式一:注解
@WebServlet
@WebFilter
@WebListener
在实现类上使用该注解即可一键注册
方式二:配置类
在@Configuration标识的配置类中通过RegistrationBean进行注册
@Bean
public ServletRegistrationBean regServlet() {
ServletRegistrationBean userServlet= new ServletRegistrationBean();
userServlet.addUrlMappings("/servlet");
userServlet.setServlet(new UserServlet());
return userServlet;
}
@Bean
public FilterRegistrationBean regFilter() {
FilterRegistrationBean userFilter = new FilterRegistrationBean();
userFilter .addUrlPatterns("/*");
userFilter .setFilter(new UserFilter ());
return userFilter ;
}
@Bean
public ServletListenerRegistrationBean<LoginSessionListener> regServletListener() {
ServletListenerRegistrationBean<LoginSessionListener> loginSessionListener= new ServletListenerRegistrationBean<LoginSessionListener>();
loginSessionListener.setListener(new LoginSessionListener());
return loginSessionListener;
}
标签:Filter,userFilter,userServlet,FilterRegistrationBean,ServletRegistrationBean,Lis From: https://www.cnblogs.com/snad/p/17272758.html