Spring 4 + metadata-complete =" false" +瓷砖3

时间:2016-12-09 17:49:19

标签: metadata web.xml spring-4 tiles-3

我面临着Spring的非常具体的问题。如果我保持元数据完整="真"在我的web.xml中,我的应用程序工作是一个魅力。但如果我把它弄错了,那么spring就无法找到瓷砖定义。

我的代码库版本如下: Spring MVC:4.3.4.RELEASE 瓷砖:3.0.7 网络应用程序:3.0

应用程序结构:一个EAR项目,在主Web应用程序和1个EJB中包含4个Web碎片jar。

我的web.xml如下

insert into exactonlinerest..DocumentAttachments
( attachment
, document
, filename
)
select file_contents
,      dct.some_guid
,      file_path
from   ( select min(id) some_guid from exactonlinerest..documents ) dct
join   files('c:\windows\system32', '*.png', false)@os
join   read_file(file_path)@os
union all
select file_contents
,      dct.some_guid
,      file_path
from   ( select min(id) some_guid from exactonlinerest..documents ) dct
join   files('c:\windows\system32', '*.exe', false)@os
join   read_file(file_path)@os

My Dispatcher servlet xml如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0" metadata-complete="true">

    <description>
    Web Module</description>
    <display-name>Web</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value> 
          <!--   classpath:/applicationContext.xml
            classpath:/applicationContext-dao-enterprise.xml  -->        
            classpath:META-INF/resources
            classpath:META-INF/resources/jsp/web1/common/
            classpath:META-INF/resources/jsp/web2/common/
        </param-value>
    </context-param>

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>


    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

我的Tiles定义如下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">



    <context:annotation-config />

    <mvc:annotation-driven />
    <mvc:default-servlet-handler />

    <tx:annotation-driven transaction-manager="txManager" />

    <mvc:resources mapping="/styles/**" location="/WEB-INF/../styles/" />
    <mvc:resources mapping="/js/**" location="/WEB-INF/../js/" />
    <mvc:resources mapping="/font-awesome/**" location="/WEB-INF/../font-awesome/" />



    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>classpath:global-messages</value>
                <value>classpath:global-resources</value>
            </list>
        </property>
    </bean>
    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
        <property name="defaultLocale" value="en_US" />
    </bean>
    <!-- Datasource bean created using Driver -->

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="jdbc/myDatasource" />
    </bean>
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <constructor-arg ref="dataSource" />
        <!--<property name="maxRows" value="${jdbcTemplate.maxRows}"/> <property 
            name="fetchSize" value="${jdbcTemplate.fetchSize}"/> -->
    </bean>
    <bean id="txManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <context:component-scan base-package="com.co" />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver"/>

    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
                <value>/WEB-INF/tiles-i.xml</value>
                <value>/WEB-INF/tiles-f.xml</value>
            </list>
        </property>
    </bean>

    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

</beans>

用于呼叫的控制器代码如下

<?xml version="1.0" encoding="UTF-8" ?>
<!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>
    <!--====================================  Master Page====================================================================  -->
     <definition name="tiles_basic_template" template="/jsp/ent/tiles/basic_template.jsp">
        <put-attribute name="title" value="Application" />
        <put-attribute name="sidemenu" value="/jsp/e/tiles/sidemenu.jsp" />
        <put-attribute name="header" value="/jsp/e/tiles/header.jsp" />
        <put-attribute name="body" value="/jsp/e/tiles/blank_body.jsp" />
        <put-attribute name="footer" value="/jsp/e/tiles/footer.jsp" />
    </definition> 

        <definition name="tiles_sign_on" template="/jsp/e/tiles/basic_template_no_header_sidebar.jsp">
        <put-attribute name="body" value="/jsp/e/common/sign_on_form.jsp" />
     </definition>

异常堆栈跟踪如下:

modelView.addObject("signOnForm", signOnForm);
modelView.addObject("buttonName", buttonName);
modelView.setViewName("tiles_sign_on");

1 个答案:

答案 0 :(得分:0)

最后,我在调试了spring source和tiles源文件后得到了答案。

问题在于项目结构分散。由于碎片化的项目结构,我们在每个片段中都有Spring Dispatcher servlet xml。现在春天有一个bug: 当web.xml具有&#34; metadata-complete =&#34; false&#34;&#34;时,spring也在片段项目中搜索它的调度程序servlet xml。但是,tile定义将从最后一个调度程序servlet的配置中被覆盖。因此,加载了最后一个片段的切片定义文件。删除所有先前的定义文件。

快速解决方案:将所有切片定义文件保留在父调度程序servlet xml中,并且所有碎片项目都不应包含它自己的配置。

长期解决方案:需要由Spring社区完成。在初始化应用程序之前,spring应该合并所有这些并创建一个主调度程序,而不是替换配置。