2015-03-03 115 views
6

我是新來的春天,並嘗試與春天使用瓷磚。但得到以上錯誤。我在我的項目中使用maven。我也嘗試過更改版本,但沒有用。以下是項目的內容:與彈簧瓷磚:獲取錯誤 - java.lang.ClassNotFoundException:org.apache.tiles.TilesApplicationContext

的pom.xml

<!-- Apache Tiles --> 
    <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-core</artifactId> 
     <version>3.0.5</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-jsp</artifactId> 
     <version>3.0.5</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-api</artifactId> 
     <version>3.0.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-servlet</artifactId> 
     <version>3.0.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-template</artifactId> 
     <version>3.0.5</version> 
    </dependency> 

的servlet-context.xml的

<!-- for Tiles --> 
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" id="viewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>    
</bean> 

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

瓷磚-definitions.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<tiles-definitions> 
    <definition name="base.definition" template="/WEB-INF/views/tilesMainTemplate.jsp"> 
     <put-attribute name="title" value=""></put-attribute> 
     <put-attribute name="header" value="/WEB-INF/views/header.jsp"></put-attribute> 
     <put-attribute name="menu" value="/WEB-INF/views/home.jsp"></put-attribute> 
     <put-attribute name="body" value=""></put-attribute> 
     <put-attribute name="footer" value="/WEB-INF/views/footer.jsp"></put-attribute> 
    </definition> 

    <definition extends="base.definition" name="saveAd"> 
     <put-attribute name="title" value="Post your free Ad"></put-attribute> 
     <put-attribute name="body" value="/WEB-INF/views/adSave.jsp"></put-attribute> 
    </definition> 


</tiles-definitions> 

然後有tilesMainTemplate,頁眉和頁腳jsp的,我不認爲有任何問題。在此方面的任何幫助將非常感謝,提前致謝。

回答

15

發現的類最後,它的工作!我換成tiles2通過tiles3由MCK作爲正確地指出,並添加以下行磚-definitions.xml中

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

這對我很有用 – 2016-07-08 02:39:42

10

在servlet-context.xml中,您正在使用tiles2 spring-tiles集成類。

改用下org.springframework.web.servlet.view.tiles3

+0

所以我應該用tiles3替換tiles2,對吧? – BhendiGawaar 2015-03-04 09:32:05

0
use this code if your are using version 3 . based on the version your are using should configure the tiles. 
<bean id="viewResolver" 
     class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property name="viewClass"> 
      <value> 
       org.springframework.web.servlet.view.tiles3.TilesView 
      </value> 
     </property> 
    </bean> 
    <bean id="tilesConfigurer" 
     class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"> 
     <property name="definitions"> 
      <list> 
       <value>/WEB-INF/estudo-tiles-servlet.xml</value> 
      </list> 
     </property> 
    </bean> 
0

使用:

import org.springframework.web.servlet.view.tiles3.TilesView; 

不:

import org.springframework.web.servlet.view.tiles2.TilesView;