2

この種の質問をもう一度して申し訳ありませんが、他のスレッドとSpring docを見て問題を解決できませんでした。

私はmavenで3.1.0.RELEASEを使用しており、注釈とJava構成を使用しようとしています。

ここに私のweb.xmlがあります:

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

<servlet>
    <servlet-name>WebAppServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/servletConf/web-application-config.xml<!-- ,
            /WEB-INF/servletConf/application-security.xml -->
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>WebAppServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

これが私のファイル web-application-config.xml です。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

<context:property-placeholder location="classpath*:META-INF/spring/*.properties" />

<context:spring-configured />

<context:component-scan base-package="testspring">
    <context:exclude-filter expression=".*_Roo_.*" type="regex" />
    <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" />
</context:component-scan>

<mvc:annotation-driven />

私は2つのクラスを持っています。最初のものはビューリゾルバーを構成します

package testspring.web;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;



@Configuration
public class CostManagerConfig {

 // Resolve logical view names to .jsp resources in the /WEB-INF/jsp directory
    @Bean
    ViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("WEB-INF/jsp/");
        resolver.setSuffix(".jsp");
        return resolver;
        }
}

そして2番目は私のコントローラを定義します:

package testspring.web;

import java.util.Comparator;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Handles requests for the application home page.
 */
@Controller

public class HomeController {

/**
     * Default page when no mapping found.
     * @return
     */
    @RequestMapping("/*")
    public String home() {
        System.out.println("HomeController: Passing through...");
        return "home";
    }

}

私が設定した内容によると、すべてが私の home() 関数に向けられるべきだと思います。ただし、ここではそうではありません。Apache が出力したログは次のとおりです。

DEBUG DispatcherServlet - [/testSpring/] の GET リクエストを処理する「WebAppServlet」という名前の DispatcherServlet

DEBUG RequestMappingHandlerMapping - パスのハンドラー メソッドの検索 / DEBUG RequestMappingHandlerMapping - [/] のハンドラー メソッドが見つかりませんでした

WARN PageNotFound - 「WebAppServlet」という名前の DispatcherServlet で、URI [/testSpring/] の HTTP 要求のマッピングが見つかりません

DEBUG DispatcherServlet - リクエストが正常に完了しました

@RequestMapping のパラメーターを変更しようとしましたが、何も変更されません...次のことを試しました

@RequestMapping("/*")

@RequestMapping()

@RequestMapping("/")

@RequestMapping("/home")

@RequestMapping("/home.html")

アクセスしようとしたURLは

http://localhost:8080/testSpring/

http://localhost:8080/testSpring/home

http://localhost:8080/testSpring/home.html

どうか私を助けていただけませんか?

読んでいただきありがとうございます!

良い1日を;)。

4

1 に答える 1

2

もちろん、コンポーネントスキャンからHomeControllerを除外したため、HomeControllerに入ることができません。

<context:component-scan base-package="testspring">
  <context:exclude-filter expression=".*_Roo_.*" type="regex" />
  <context:exclude-filter expression="org.springframework.stereotype.
  Controller" type="annotation" />
</context:component-scan>

したがって、この行にコメントするだけです。

<context:exclude-filter expression="org.springframework.stereotype.
Controller" type="annotation" />
于 2012-08-15T19:32:11.900 に答える