Bonjour à tous,
je débute en spring MVC. Je tente de faire fonctionner un "hello world" mais j'obtiens une erreur 404.
J'ai généré mon projet avec gradle. Voici le fichier build.gradle :
Voici le contenu de mon web.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 apply plugin : 'war' apply plugin : 'eclipse-wtp' springVersion = "3.0.6.RELEASE" sourceCompatibility = 1.6 slf4jVersion = "1.6.1" group = 'com.springsourcery.helloWorld' version = '1.0' repositories { mavenCentral() } dependencies{ compile "org.slf4j:jcl-over-slf4j:$slf4jVersion","org.slf4j:jul-to-slf4j:$slf4jVersion" compile "org.springframework:spring-webmvc:$springVersion" compile "javax.servlet:servlet-api:2.5" compile "javax.faces:jsf-api:1.2_02" compile "javax.faces:jsf-impl:1.2-b19" compile "javax.servlet:jstl:1.1.2", "taglibs:standard:1.1.2" runtime "org.slf4j:slf4j-log4j12:$slf4jVersion" testCompile "junit:junit:4.8.2" testCompile "org.springframework:spring-test:$springVersion" }
Voilà le contenu du fichier web-application-config.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 <?xml version="1.0" encoding="ISO-8859-1"?> <web-app 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_4.xsd" version="2.4"> <!-- The front controller of the Spring MVC Web application, responsible for handling all application requests --> <servlet> <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/web-application-config.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- Map requests to the DispatcherServlet for handling --> <servlet-mapping> <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
Voici le contenu du fichier index.jsp :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 <?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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <mvc:annotation-driven/> <!-- Scan for annotation based controllers --> <context:component-scan base-package="com.springsourcery" /> <bean id="viewResolver" 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> </beans>
Et enfin le contenu de mon controlleur 'HelloWorldController' :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%-- Redirected because we can't set the welcome page to a virtual URL --%> <c:redirect url="/hello" />
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package bruno.leduic.helloworld; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping("/hello") public class HelloWorldController { @RequestMapping(method = RequestMethod.GET) public String showHello(Model model, HttpServletRequest request) { return "hello"; } }
Le détail de l'erreur que j'obtiens en naviguant sur http://localhost:8080/HelloWorld :
Merci pour votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 Etat HTTP 404 - /HelloWorld/hello type Rapport d'état message /HelloWorld/hello description La ressource demandée n'est pas disponible. Apache Tomcat/6.0.36
Partager