2010-11-22 11 views
4

Je fais des tests avec spring mvc et j'ai un problème. Pour une application de base à tester avec je choisis ce tutoriel: http://loianegroner.com/2010/09/extjs-spring-mvc-3-and-hibernate-3-5-crud-datagrid-example/ J'ai téléchargé l'exemple et tout fonctionne comme prévu. Le problème est quand j'essaie d'ajouter un autre contrôleur. Il semble que le fichier que j'ajoute n'est pas scanné.Spring MVC Contrôleurs non enregistrés

Mon fichier web.xml:

<servlet> 
    <servlet-name>extjs-crud-grid-spring-hibernate</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/spring/app-config.xml 
     </param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>extjs-crud-grid-spring-hibernate</servlet-name> 
    <url-pattern>*.action</url-pattern> 
</servlet-mapping> 

/WEB-INF/spring/app-config.xml:

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
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-3.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

<!-- Scans the classpath of this application for @Components to deploy as beans --> 
<context:component-scan base-package="com.loiane" /> 

<!-- Configures the @Controller programming model --> 
<mvc:annotation-driven /> 

<!-- misc --> 
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
    <property name="suffix" value=".jsp"/> 
</bean> 

<!-- Configures Hibernate - Database Config --> 
<import resource="db-config.xml" /> 

comme vous pouvez le voir, il y a le contexte: composants -scan et mvc: balises pilotées par des annotations qui devraient indiquer au ressort d'analyser toutes les classes du package com.lione pour l'annotation @Controller. Mais quand j'essaie d'ajouter mon propre contrôleur à cette application, il semble que ce n'est pas traité. Seul le premier contrôleur est mappé.

Voici mon code de contrôleur

package com.loiane.web; 


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


@Controller 
public class HelloController { 

    @RequestMapping("/helloWorld.action") 
    public ModelAndView helloWorld() { 
     ModelAndView mav = new ModelAndView(); 
     mav.setViewName("helloWorld"); 
     mav.addObject("message", "Hello World!"); 
     return mav; 
    } 
} 

Après avoir exécuté ce dans le journal de la console Eclipse J'ai

INFO: Mapped URL path [/contact/delete.action] onto handler 'contactController' 
INFO: Mapped URL path [/contact/create.action] onto handler 'contactController' 
INFO: Mapped URL path [/contact/update.action] onto handler 'contactController' 
INFO: Mapped URL path [/contact/view.action] onto handler 'contactController' 

mais /helloWorld.action est manquant

Merci à l'avance

+0

Tout semble bien. Peut-être pour une raison quelconque votre contrôleur n'est pas ajouté à la webapp que vous exécutez. – axtavt

+0

d'une manière ou d'une autre je l'ai fait cartographier. Je ne sais pas où était le problème mais après avoir créé un nouveau projet et réimporté tous les fichiers, il a commencé à fonctionner. – Ivan

+3

vous voudrez peut-être clôturer cette question pour éviter que d'autres ne trébuchent dessus par erreur –

Répondre

3

Parfois, c'est une bonne idée d'être plus précis avec votre chemin lorsque vous utilisez <context:component-scan base-package="package-name" /> Donc, vous devriez faire <context:component-scan base-package="com.loiane.web" />