0

SpringSource Tool Suite 2.9.2 を使用して、プロジェクトを作成しました

新規 > Spring テンプレート プロジェクト > Spring MVC プロジェクト

これにより、単純なコントローラー pom.xml、servlet-context.xml、root-context.xml、およびコントローラーがマップされる単純な jsp ファイルが生成されます。

/resources/**しかし、プロジェクトを実行すると、 で指定されているようにパスがリソース サーブレットにマップされているにもかかわらず、コントローラがコンポーネント スキャンによって検出されませんservlet-context.xml。Hello World を表示するはずのページが 404 を表示しています。

私は何を間違っていますか?

の関連ビットservlet-context.xml:

<context:component-scan base-package="com.test.hello" />

com.test.hello.HomeController.java:

@Controller
public class HomeController {
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Locale locale, Model model) {
        model.addAttribute("serverTime", new Date());
        return "home";
    }
}

そしてエラーメッセージ:

WARN : org.springframework.web.servlet.PageNotFound - 名前が「appServlet」の DispatcherServlet で、URI [/] の HTTP リクエストのマッピングが見つかりません

の内容web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>
4

2 に答える 2

2

プロジェクトの単純なクリーンアップとビルドにより、この問題が修正されました!

于 2012-09-28T09:35:10.233 に答える