分别通过构建下面bean来,使用filter,servlet,servletlistener
FilterRegistrationBean 、
ServletRegistrationBean 、
ServletListenerRegistrationBean
这三个类
直接上代码:
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
registrationBean.setFilter(characterEncodingFilter);
return registrationBean;
}
@Bean
public ServletRegistrationBean servlet(){
return new ServletRegistrationBean();
}
@Bean
public ServletListenerRegistrationBean<EventListener>(){
return new ServletListenerRegistrationBean<>(new EventListener());
}