我试着替换web.xml文件使用java配置(我使用Spring,但没有使用Spring引导)。我移动了web.xml文件像在下面的代码中添加过滤器、servlet和侦听器:
public class ServletInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(MyApplication.class);
servletContext.addListener(new ContextLoaderListener(context));
addFilters(servletContext);
addServlets(servletContext, context);
}
private void addServlets(ServletContext servletContext, AnnotationConfigWebApplicationContext context) {
ServletRegistration.Dynamic dispatcher = servletContext
.addServlet("DispatcherServlet", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
ServletRegistration.Dynamic mvcServlet = servletContext
.addServlet("MvcServlet", new DispatcherServlet(context));
mvcServlet.setLoadOnStartup(1);
mvcServlet.addMapping("/mvc/*");
}
private void addFilters(ServletContext servletContext) {
servletContext.addFilter("characterEncoding", new CharacterEncodingFilter("UTF-8", true))
.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
servletContext.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class)
.addMappingForUrlPatterns(null, false, "/*");
servletContext.addFilter("i18nOutputFilter", DelegatingFilterProxy.class)
.addMappingForUrlPatterns(
EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
}
}
不幸的是,我不知道如何处理这些元素:
Unsecured website
/mvc/extNavigation/*
GET
authenticated
Access to use the Secured web site - authenticated
authenticated
FORM
/loginSSO.jsp
/errorSSO.jsp