Привет всем, я знаю, что были десятки подобных вопросов, но я не мог найти решение, которое работает для меня. Я хочу сделать простое приложение «hello world», используя весенний mvc. Это дает мне сообщение об ошибке 404, и на консоли:Не найдено сопоставления для HTTP-запроса с URI [.../helloworld.xhtml] в DispatcherServlet с именем 'dispatcher'
avr. 22, 2015 4:10:42 PM org.springframework.web.servlet.PageNotFound noHandlerFound
AVERTISSEMENT: No mapping found for HTTP request with URI [/SpringMVC/WEB- INF/views/helloworld.xhtml] in DispatcherServlet with name 'dispatcher'
pom.xml
<properties>
<spring.version>4.1.6.RELEASE</spring.version>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
web.xml
<web-app>
<display-name>Archetype Created Web Application</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>
WEB-INF/диспетчеру-сервлет .xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.xhtml</value>
</property>
</bean>
</beans>
Контроллер
package com.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class SpringController {
String message = "Welcome to Spring MVC!";
@RequestMapping("/hello")
public ModelAndView showMessage(@RequestParam(value = "name", required = false, defaultValue = "World") String name) {
System.out.println("in controller");
ModelAndView mv = new ModelAndView("helloworld");
mv.addObject("message", message);
mv.addObject("name", name);
return mv;
}
}
index.xhtml
<html>
<body>
<h2>Hello World!</h2>
<h3>
<a href="hello?name=youness">Click Here</a>
</h3>
</body>
</html>
WEB-INF/просмотров/helloworld.xhtml
<html>
<head>
<title>Spring 4 MVC -HelloWorld</title>
</head>
<body>
<h2>Hello World</h2>
<h2>
${message} ${name}
</h2>
</body>
</html>
и когда я нажимаю на ссылку «нажмите здесь»
им получать эту ошибку:
avr. 23, 2015 2:48:58 PM org.springframework.web.servlet.PageNotFound noHandlerFound
AVERTISSEMENT: No mapping found for HTTP request with URI [/SpringMVC/WEB- INF/views/helloworld.xhtml] in DispatcherServlet with name 'dispatcher'
привет спасибо за ваше предложение, но не работал для меня. консоль: avr. 27, 2015 11:59:44 AM org.springframework.web.servlet.PageNotFound noHandlerFound AVERTISSEMENT: сопоставления не найдено для HTTP-запроса с URI [/ SpringMVC] в DispatcherServlet с именем 'dispatcher' –