我正在构建 Spring 4 MVC 应用程序。我已经将 sitemesh 与我的项目集成了......但是,我正在尝试准备无 XML 配置 - 我没有 web.xml 文件,当然我想将我的装饰器配置移动到 Java Config 类中。可以用那种方式配置我的装饰器吗?
最佳答案
我不确定 sitemesh v2。我查看了他们的文档,但找不到与 Java 配置相关的任何内容。如果您更新到 v3,您可以继承 ConfigurableSiteMeshFilter 并覆盖 applyCustomConfiguration 方法。更多信息请访问 http://wiki.sitemesh.org/wiki/display/sitemesh3/Configuring+SiteMesh+3 .下面提供的链接示例
public class MySiteMeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
// Map default decorator. This shall be applied to all paths if no other paths match.
builder.addDecoratorPath("/*", "/default-decorator.html")
// Map decorators to path patterns.
.addDecoratorPath("/admin/*", "/another-decorator.html")
.addDecoratorPath("/*.special.jsp", "/special-decorator.html")
// Map multiple decorators to the a single path.
.addDecoratorPaths("/articles/*", "/decorators/article.html",
"/decoratos/two-page-layout.html",
"/decorators/common.html")
// Exclude path from decoration.
.addExcludedPath("/javadoc/*")
.addExcludedPath("/brochures/*");
}
}
关于java - Spring 4 + Sitemesh 与 Java 配置和没有 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23527833/