I had a working implementation of the SiteMeshFilter in my project, but since moving to extending AbstractAnnotationConfigDispatcherServletInitializer instead of WebApplicationInitializer my sitemesh filter isn't being used.
I've been trying to understand the following tutorials on Spring security http://blog.springsource.org/2013/07/03/spring-security-java-config-preview-web-security/ and http://tux2323.blogspot.co.uk/
Not sure if Security is getting in the way or I've mis-configured the Initializer/Dispatcher somehow....
The old config (extending 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);
}
New config (extending 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};
}
The other config classes/SitemeshFilter haven't changed so I'm reasonably happy they are ok. Indeed I get a page complete with data from database when I hit the site, but it simply hasn't been styled up by Sitemesh. Possible the sitemesh filter isn't being hit?
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");
}
}