Я новичок в Spring MVC, и я пытаюсь запустить свое первое приложение, но я получаю следующую ошибку. Я не уверен, что случилось с моим кодом, но я получаю следующее сообщение об ошибке:Нет сопоставления для HTTP-запроса с URI [/ FirstSpringMVCApp /] в DispatcherServlet с именем «spring-dispatcher»
No mapping found for HTTP request with URI [/FirstSpringMVCApp/] in DispatcherServlet with name 'spring-dispatcher'
Вот мой web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>FirstSpringMVCApp</display-name>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
Вот мой диспетчеру файл:
<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.spring.test"></context:component-scan>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
Вот мой контроллер
package com.spring.test;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HelloController {
@RequestMapping("/hellospring")
public String printHello(ModelMap model){
model.addAttribute("message", "Hello spring...");
return "hello";
}
}
Вот мой файл jsp:
<html>
<head></head>
<body>
<h1>Message : ${message}</h1>
</body>
</html>
Любая помощь?
Не совсем * для запуска приложения *, но скорее для того, чтобы нажать на контроллер *, поскольку ваш '@ RequestMapping' объявляет URL (относительно контекста)'/hellospring'. –