java - Spring 4 + Sitemesh 与 Java 配置和没有 xml

标签 java xml spring-mvc sitemesh

我正在构建 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/

相关文章:

java - OJB 引用描述符 1 :0 relationship? 我是否应该将自动检索设置为 false?

Java - CSVReader 在值中用逗号正确分割

asp.net - 如何使用来自 asp.net 的 webrequest 将 xml 发送到 asp 页面?

java - 在 Spring 中,如何将自定义参数自动填充到 web @Controller 方法?

java - 无法让基本的 Hello World Spring MVC 项目正常工作

java - 如何释放jbyteArray?

java - 与数据库无关的数据库加密

java - JAXB2,如何根据包含 xsd :any element? 的 XML 架构进行部分验证

Java 将 XML 文档 append 到现有文档

spring - 创建自定义AuthenticationSuccessHandler并在完成后调用默认的AuthenticationSuccessHandler