URLを使用すると.. .. http://localhost:8080/springdemo/hello
404 not foundエラーが表示されます.. Mavenプロジェクトでいつものように、Javaファイルをsrc/main/java内に配置しました。私のコントローラーコードは次のとおりです:-
package org.abhishek;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import java.lang.System;
@Controller
public class HelloWorldController {
@RequestMapping(value="/hello", method = RequestMethod.GET)
public ModelAndView helloWorld() {
System.out.println("hello**");
String message = "Hello World, Spring MVC @ Javatpoint";
return new ModelAndView("hello", "message", message);
}
}
以下の Web.xml ファイル
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="java.sun.com/xml/ns/javaee"; xmlns:xsi="w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="java.sun.com/xml/ns/javaee java.sun.com/xml/ns/javaee/web-app_2_5.xsd">;
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app>
デバッグ目的でこの行System.out.println()
を挿入したところ、上記の URL ではこのメソッドが実行されないことがわかりました...つまりhttp://localhost:8080/springdemo/hello
、事前に回答してください..ありがとうございます。