После инициализации компонента я получаю исключение, так как обработчик не найден, но я использую аннотацию контроллера.
May 28, 2019 4:04:57 PM org.springframework.web.servlet.FrameworkServlet initServletBean INFO: Completed initialization in 836 ms May 28, 2019 4:04:57 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping for GET /SpringMVCProjectTutorial09/ May 28, 2019 4:05:04 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping for GET /SpringMVCProjectTutorial09/welcome
Java-файл
package com.maddus.program; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class WelcomeToSpringMVCController { @RequestMapping(value="/welcome") public ModelAndView DisplayMessage() { ModelAndView model = new ModelAndView("WelcomeNote"); model.addObject("msg", "Hello Maddu....\nWelcome to Spring MVC"); return model; } }
весна-диспетчерская-servlet.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" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <mvc:annotation-driven /> <context:component-scan base-package="com.maddus.program.WelcomeToSpringMVCController" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean>
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" version="3.1"> <display-name>SpringMVCProjectTutorial09</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>