spring with spring:getting error - java.lang.ClassNotFoundException:org.apache.tiles.TilesApplicationContext

时间:2015-03-03 06:36:04

标签: spring maven apache-tiles

我是Spring的新手,并试图在Spring中使用tile。但是犯了错误。我在我的项目中使用maven。我也尝试过更改版本,但没有用。以下是项目内容:

的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的,我认为没有任何问题。在这方面的任何帮助将受到高度赞赏,在此先感谢。

4 个答案:

答案 0 :(得分:17)

最后它奏效了!我按照mck正确指出的tiles3替换了tiles2,并将以下行添加到 tiles-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">

答案 1 :(得分:11)

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

使用org.springframework.web.servlet.view.tiles3下找到的类

答案 2 :(得分: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>

答案 3 :(得分:0)

使用:

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

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