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

4

10

I am new to spring and trying to use tiles with Spring. but getting above error. i am using maven in my project. i tried changing versions also, but no use. following are contents of project:

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>

tiles-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>  

then there are tilesMainTemplate, header and footer jsp's which i dont think have any issues. any help in this regard will be highly appreciated, Thanks in advance.

Cerargyrite answered 3/3, 2015 at 6:36 Comment(0)
P
13

In your servlet-context.xml you are using the tiles2 spring-tiles integration classes.

Use instead the classes found under org.springframework.web.servlet.view.tiles3

Parapet answered 4/3, 2015 at 7:36 Comment(1)
Changed doctype as follows and it worked, thanks. <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">Cerargyrite
C
1

Use this code if you are using version 3 . based on the version you 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>
Chromatology answered 21/2, 2016 at 4:47 Comment(0)
C
0

Using:

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

Not:

import org.springframework.web.servlet.view.tiles2.TilesView;
Considering answered 15/9, 2016 at 3:20 Comment(0)
E
0

1 ) In WEB-INF folder need to place the tiles-definitions.xml

WEB-INF\tiles-definitions.xml

<?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">

2 ) Add the below mentioned dependencies in pom.xml

        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-core</artifactId>  
            <version>3.0.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-api</artifactId> 
            <version>3.0.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-servlet</artifactId> 
            <version>3.0.8</version>
        </dependency>
        
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-template</artifactId>  
            <version>3.0.8</version>
        </dependency>
        
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-el</artifactId> 
            <version>3.0.8</version>
        </dependency>
        </dependency> 
            <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-master</artifactId>
            <version>6</version> or 
            <version>7</version>
        </dependency>

3 ) Provide the concern classes in servlet-context.xml

<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="tilesConfigurerId"
    class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles-config_3_0.dtd</value>
        </list>
    </property>
</bean> 
Epicureanism answered 5/9, 2022 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.