2012-11-23 13 views
5

Ho lavorato su questo per un po 'ora e semplicemente non ho idea di cosa sia sbagliato. Sto distribuendo un'applicazione Spring 3.1 MVC su Tomcat 7. Dall'esame DEBUG, posso vedere che 1) Il servlet dispatcher MVC ottiene tutti i miei URL come richiesto 2) tutti gli URL associati alle annotazioni dei controller funzionano bene 3) Qualsiasi URL che Ho bisogno di essere mappato a JSP ottenere un 404. Inoltre, sto usando JDK 1.7.0_09. Le mie pagine JSP sono in/WEB-INF/jsp /.Spring mvc 3.1 tomcat 7 - 404 non risolvendo jsp ma le annotazioni del controller funzionano bene

Grazie in anticipo per eventuali suggerimenti che potrei perdere!

Ecco il mio web.xml:

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

    <display-name></display-name> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> 
    </context-param> 

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

    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

ho cercato di modificare il mio modello di URL a /,/, /.,. "/" sembra portarmi il più lontano finora. Inoltre, potrei sbagliarmi, ma non penso che l'URL sia il problema dato che i registri di DEBUG mostrano che tutti gli URL stanno andando al servlet del dispatcher, che è quello che voglio.

Ecco il mio dispatcher-servlet.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:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.1.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> 

    <!--Tell the servlet where to look for annotated methods--> 
    <context:component-scan base-package="com.test.web.mvc.ctrl" /> 

    <!--Enables many annotations and searches for @Controller annotated methods etc.. --> 
    <context:annotation-config /> 

    <!--JSR-303 (Bean validation) support will be detected on classpath and enabled automatically--> 
    <mvc:annotation-driven /> 

    <!--This tag allows for mapping the DispatcherServlet to "/" (all extensions etc)--> 
    <mvc:default-servlet-handler/> 

    <!-- ControllerClassNameHandlerMapping --> 
    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
     <property name="prefix" value="/WEB-INF/jsp/"/> 
     <property name="suffix" value=".jsp"/> 
    </bean> 

    <bean class = "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" /> 
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" /> 
</beans> 

cerco di inviare più di un URL di http://localhost:8080/hello. La mia applicazione è distribuita su "/" e il resolver non mappa la vista "/ home" su /WEB-INF/jsp/hello.jsp nonostante i registri di DEBUG mostrino che riconosce correttamente che "/ home" è la vista in entrata nome.

http://localhost:8080/rest/user/bob_user funziona in modo ottimale ed è mappato su un'annotazione di Controller.

Qualsiasi aiuto sarebbe molto apprezzato! Grazie!

Aggiornamento: Qui ci sono i registri di debug per http://localhost:8080/hello che dovrebbe tradursi in /WEB-INF/jsp/hello.jsp

2012-11-23 03:45:50,089 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/hello] 
2012-11-23 03:45:50,089 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework[email protected]5c9a010c] in DispatcherServlet with name 'dispatcher' 
2012-11-23 03:45:50,089 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /hello 
2012-11-23 03:45:50,093 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/hello] 
2012-11-23 03:45:50,093 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler map [[email protected]49049c10] in DispatcherServlet with name 'dispatcher' 
2012-11-23 03:45:50,093 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - No handler mapping found for [/hello] 
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler map [or[email protected]17bd11ee] in DispatcherServlet with name 'dispatcher' 
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping - No handler mapping found for [/hello] 
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler map [[email protected]f212a54] in DispatcherServlet with name 'dispatcher' 
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/hello] are [/**] 
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/hello] are {} 
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/hello] to HandlerExecutionChain with handler [org.spring[email protected]4a61f88e] and 1 interceptor 
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler adapter [org.springframework[email protected]1a33f07b] 
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler adapter [[email protected]f128ad] 
2012-11-23 03:45:50,094 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/hello] is: -1 
2012-11-23 03:45:50,095 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling 
2012-11-23 03:45:50,095 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Cleared thread-bound request context: [email protected] 
2012-11-23 03:45:50,095 [http-bio-8080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request 
2012-11-23 03:45:50,095 [http-bio-8080-exec-8] DEBUG org.springframework.web.context.support.XmlWebApplicationContext - Publishing event in WebApplicationContext for namespace 'dispatcher-servlet': ServletRequestHandledEvent: url=[/hello]; client=[127.0.0.1]; method=[GET]; servlet=[dispatcher]; session=[D81D9C8BE397827739EB48BC3BB7A35D]; user=[null]; time=[7ms]; status=[OK] 
2012-11-23 03:45:50,095 [http-bio-8080-exec-8] DEBUG org.springframework.web.context.support.XmlWebApplicationContext - Publishing event in Root WebApplicationContext: ServletRequestHandledEvent: url=[/hello]; client=[127.0.0.1]; method=[GET]; servlet=[dispatcher]; session=[D81D9C8BE397827739EB48BC3BB7A35D]; user=[null]; time=[7ms]; status=[OK] 
+0

La registrazione è abilitata? Cosa dice il registro? –

+0

Aggiornerò il post per riflettere i registri di debug ... – avrao

+0

E il controller restituisce "casa", giusto? –

risposta

0

Forse il tuo MVC: annotazioni-driven è prevalente il tuo RequestMappingHandlerMapping.

escludere anche le classi @Controller dal componente-scan:

<context:component-scan base-package="org.example"> 
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> 
</context:component-scan> 

perché i controllori si trovano già da

0

così .. ho avuto questo problema con la creazione di una nuova classe di controllo che ha un metodo con un @RequestMapping("/{viewName}"). Il modo in cui Spring MVC corrisponde, questa dovrebbe essere l'ultima e più generica corrispondenza. Di conseguenza, se ottengo l'URL, proverà a far corrispondere gli altri Controller per poi abbinarli all'ultimo. Quando corrisponde, restituisco semplicemente una stringa con il nome della vista, quindi alla fine andrà a /WEB-INF/jsp/[view-name].jsp. Qualcuno ha un'idea migliore? Grazie!

Problemi correlati