2011-07-20 14 views
0

Spring MVC 3とApache Tiles 2をうまく組み合わせようとしています。私は表示する単純なページを得ることができ、それらのページはTilesテンプレートで構築されていますが、私の人生では私のコントローラを呼び出すことができません。助けていただければ幸いです。Spring MVC 3とApache Tiles 2、しかしコントローラーなし

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/j2ee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"> 

    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

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

    <servlet> 
     <servlet-name>tiles</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value></param-value> 
     </init-param> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>tiles</servlet-name> 
     <url-pattern>*.html</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 

</web-app> 

web-application-context.xml

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

    <!-- Imports the configurations of the different infrastructure systems of the application --> 
    <import resource="webmvc-context.xml" /> 

</beans> 

webmvc-context.xml

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

    <!-- Static resource mapping (css, js, images, etc) --> 
    <mvc:resources mapping="/resources/**" location="/WEB-INF/resouces/" /> 

    <!-- Required stuff for autowiring of controllers --> 
    <context:annotation-config /> 
    <context:component-scan base-package="com.tarigmaa.gem" /> 
    <mvc:annotation-driven/> 
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> 
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> 

    <!-- Static views (no controller) --> 
    <!-- <mvc:view-controller path="/index.html" /> --> 

    <!-- Tiles initialization --> 
    <bean id="tilesConfigurer" 
      class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" 
      p:definitions="/WEB-INF/tiles-defs/templates.xml" /> 

    <bean id="tilesViewResolver" 
      class="org.springframework.web.servlet.view.UrlBasedViewResolver" 
      p:viewClass="org.springframework.web.servlet.view.tiles2.TilesView" /> 

    <!-- Map URLs to controllers --> 
    <bean id="urlMapping" 
      class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
     <property name="alwaysUseFullPath" value="true" /> 

     <property name="mappings"> 
      <props> 
       <prop key="/index.html">exampleController</prop> 
       <prop key="/index2.html">exampleController</prop> 
      </props> 
     </property> 
    </bean> 

    <!-- Define the controllers --> 
    <bean id="exampleController" class="com.tarigma.GEM.HomeController" /> 

</beans> 

com.tarigma.GEM.HomeController

package com.tarigma.GEM; 

import java.util.Locale; 

import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

/** 
* Handles requests for the application home page. 
*/ 
@Controller 
public class HomeController { 

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class); 

    @RequestMapping(value = "/index.html", method = RequestMethod.GET) 
    public String home(Locale locale, Model model) { 
     logger.info("Welcome from /index.html"); 
     model.addAttribute ("title", "Nik"); 
     return "index"; 
    } 

    @RequestMapping(value = "/index2.html", method = RequestMethod.GET) 
    public String home2(Locale locale, Model model) { 
     logger.info ("Welcome from /index2.html"); 
     model.addAttribute("title", "Jeff"); 
     return "index2"; 
    } 
} 

私はここにたくさんのコードを投棄していることを知っています。私はそれを謝ります。私はこれに数日間いましたが、私は忍耐を使い果たしています。前もって感謝します。

答えて

0

あなたのRequestMappingは "/ index"または "/ index2"ではなく "/ index2"でなければなりません。サーブレットマッピング "* .html"は、SpringのDispatcherServletが呼び出しを確実に処理するようにします。

関連する問題