こんにちは、私は春には単純なMVCのサンプルを試していますが、 "/ ModelAndViewDemo/listUsers"というURLをロードすると404エラーが発生します。私は以下の例外を得る。私は同様の質問から多くの解決策を試しましたが、うまくいきませんお知らせ下さい。org.springframework.web.servlet.DispatcherServlet noHandlerFoundエラー
2017年9月9日午前8時54分51秒PM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING:URI でHTTPリクエストが見つかりませんマッピング[/ ModelAndViewDemo/listUsers]名前を持つのDispatcherServletに「ディスパッチャ以下
は私のコードです:
ディスパッチャ-servlet.xml:
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="org.manjosh.*" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
のweb.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
コントローラクラス:
package com.manjosh.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
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 com.manjosh.model.User;
import com.manjosh.service.UserService;
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping(value = "/listusers", method = RequestMethod.GET)
public ModelAndView registerSuccess() {
ModelAndView modelAndView = new ModelAndView("UserList");
List<User> userlist = userService.getUserList();
modelAndView.addObject("userList", userlist);
return modelAndView;
}
}
私はurl "http:// localhost:8080/ModelAndViewDemo/listusers"と呼ばれましたが、同じエラーが表示されます。 – manjosh
'ModelAndViewDemo'なしで'/listusers'だけを呼び出すとどうなりますか? – JohnnyAW
@manjoshあなたのアプリをどのように配備しますか?どのコンテナを使用していますか? – JohnnyAW