0

I'm rying to launch my webpage using maven, spring,hibernate, tiles.... My problem is when I add dependency for tiles in pom file and run "mvn clean package" I alway get error 404, no matter what page I'm trying to access. When I delete this dependency and chage for "InternalViewResolver" everything works fine. Need some help. Here is my files.

web.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" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">


<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- <listener>
<listener-class>org.apache.tiles.web.startup.TilesListener</listener-class>
</listener> -->

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

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

<welcome-file-list>
    <welcome-file>home</welcome-file>
</welcome-file-list>

root context:

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

</beans>

servlet context:

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

xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven/>
<context:annotation-config/>
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->


<mvc:resources mapping="/resources/**" location="/resources/" />

    <context:component-scan base-package="com.controller.*, com.models.*" />



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

        <beans:bean id="viewResolver" 
                class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
                <beans:property name="viewClass"> 
                        <beans:value> 
                                org.springframework.web.servlet.view.tiles3.TilesView 
                        </beans:value> 
                          </beans:property> 
        </beans:bean> 


    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/myonlineshopdb"/>
    <property name="username" value="stacy"/>
    <property name="password" value="stacy"/>
    </bean> 

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan"
            value="com.entities" />
        <property name="hibernateProperties">
            <props>
                <prop key="dialect">org.hibernate.dialect.MySQLDialect</prop>
            </props>
        </property>
    </bean>

    <tx:annotation-driven />
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean   class="org.springframework.dao.annotation.
     PersistenceExceptionTranslationPostProcessor"/>      

    </beans>

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

<tiles-definitions>
<definition name="management" template="/WEB-INF/views/shared/management.jsp">
    <put-attribute name="left" value="/WEB-INF/views/shared/left.jsp"/>
    <put-attribute name="body" value=""/>
</definition>

<definition name="brands" extends="management">
    <put-attribute name="body" value="/WEB-INF/views/management/brands.jsp"/>
</definition>

<definition name="home" template="/WEB-INF/home.jsp"/>
</tiles-definitions>

And two controllers that are not called at all, while tiles dependencies included to my project:

package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/home")
public class Home {

@RequestMapping("/")
public String welcome(){
    return "home";
}

}


package com.controller.management;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;  
import org.springframework.web.bind.annotation.RequestMapping;  
import org.springframework.web.servlet.ModelAndView;  
import com.dao.BrandsDao;

@Controller  
@RequestMapping("/management") 
public class BrandsController{  

@Autowired
private BrandsDao brandsDao;

@RequestMapping(value="/brands")  
public ModelAndView showBrands() {  

System.out.println("from controller");  
return new ModelAndView("brands", "brands", brandsDao.getAllBrandValues());  
}  
}  
uLYsseus
  • 995
  • 6
  • 16
  • 37
stacy
  • 11
  • 1
  • 10
  • Also just found another problem, wich I think directly connected to the first one. When I'm running my test, wich loads beans from spring, I get: error creating bean with name "tilesConfigurer". – stacy Aug 07 '14 at 10:53

1 Answers1

0

I had a similar problem, I didnt scan through every line,

  • Please remember that you need at least a Spring 3.2.x (i think 3.2.7) version to support tiles 3 I know you mentioned spring 4 , but just wanted to put this on check list.

** Most importantly make sure you have the following jars

  1. commons-beanutils-1.8.0
  2. commons-digester-2.0
  3. jcl-over-slf4j-1.7.6
  4. slf4j-api-1.7.6

As this post is quite recent one, As you said are using Spring 4.x. Make sure your dependency is (maven)

<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-extras</artifactId>
    <version>${tiles-version}</version>
</dependency>

Let me know if that helped. Thanks.

uLYsseus
  • 995
  • 6
  • 16
  • 37