我在我的项目中有一个 SiteMeshFilter 的工作实现,但是自从转移到扩展 AbstractAnnotationConfigDispatcherServletInitializer 而不是 WebApplicationInitializer 之后,我的 sitemesh 过滤器没有被使用。
我一直在尝试了解以下有关 Spring 安全的教程http://blog.springsource.org/2013/07/03/spring-security-java-config-preview-web-security/和http://tux2323。 blogspot.co.uk/
不确定安全性是否妨碍了我,或者我以某种方式错误配置了初始化程序/调度程序......
旧配置(扩展 WebApplicationInitializer):
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("yhj dispatcher", new DispatcherServlet(applicationContext));
dispatcher.addMapping("/");
dispatcher.setLoadOnStartup(1);
servletContext.addFilter("sitemeshFilter", new SitemeshFilter()).addMappingForUrlPatterns(null, false, "/*");
applicationContext.register(MvcConfiguration.class);
}
新配置(扩展 AbstractAnnotationConfigDispatcherServletInitializer):
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
}
@Override
protected String[] getServletMappings() {
return new String[] {"/"};
}
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] {SecurityConfig.class};
}
@Override
protected Filter[] getServletFilters() {
return new Filter[]{new SitemeshFilter(), new DelegatingFilterProxy("springSecurityFilterChain") };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] {MvcConfiguration.class, PersistanceConfig.class};
}
其他配置类/SitemeshFilter 没有改变,所以我很高兴他们没问题。事实上,当我访问该站点时,我会从数据库中获得一个完整的页面,但它根本没有被 Sitemesh 设计。可能没有点击sitemesh过滤器?
SitemeshFilter.java:
public class SitemeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder.setMimeTypes("text/html", "application/xhtml+xml");
builder.addDecoratorPath("/*", "/WEB-INF/templates/page.jsp");
}
}