平铺模板有时未加载

时间:2015-11-04 13:36:09

标签: java spring spring-mvc tiles

我们在Spring MVC应用程序中使用Tiles 3.有时(每5或10次服务器启动)模板都没有加载。仅显示没有页眉和页脚的.jsp页面。你有什么建议吗?

SpringConfig

@Bean
    public InternalResourceViewResolver getInternalResourceViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix(JSP_PREFIX);
        resolver.setSuffix(JSP_SUFFIX);
        return resolver;
    }


    @Bean
    public TilesConfigurer tilesConfigurer() {
        TilesConfigurer tilesConfigurer = new TilesConfigurer();
        String[] defintions = new String[] { TILES_DEF };
        tilesConfigurer.setDefinitions(defintions);
        return tilesConfigurer;
    }

    @Bean
    public ViewResolver viewResolver() {
        TilesViewResolver viewResolver = new TilesViewResolver();
        viewResolver.setCacheUnresolved(false);
        return viewResolver;
    }

tiles-definition.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE tiles-definitions
  PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3.0.dtd">

<tiles-definitions>

    <definition name=".mainTemplate" template="/WEB-INF/jsp/fragments/template.jsp">
        <put-attribute name="header" value="/WEB-INF/jsp/fragments/header.jsp" />
        <put-attribute name="body" value="/WEB-INF/jsp/fragments/body.jsp" />
        <put-attribute name="footer" value="/WEB-INF/jsp/fragments/footer.jsp" />
    </definition>



    <definition name="vermittlerUebersicht" extends=".mainTemplate">
        <put-attribute name="body" value="/WEB-INF/jsp/vermittlerUebersicht.jsp" />
    </definition>

</tiles-definitions>

和template.jsp

<!DOCTYPE html>
<%@ page pageEncoding="UTF-8" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>


    <tiles:insertAttribute name="header" />
    <tiles:insertAttribute name="body" />
    <tiles:insertAttribute name="footer" />

寻求帮助!

1 个答案:

答案 0 :(得分:0)

我找到了解决方案!我在spring配置中有2个viewresolvers。因此,不确定首先处理请求的是哪个viewresolver。我必须设置viewresolvers的顺序。 InternalResourceViewResolver必须具有最低优先级(==高位订单号)。