Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring:映射请求中出错(找不到URI为的HTTP请求的映射)_Java_Spring - Fatal编程技术网

Java Spring:映射请求中出错(找不到URI为的HTTP请求的映射)

Java Spring:映射请求中出错(找不到URI为的HTTP请求的映射),java,spring,Java,Spring,很抱歉再次提出此类问题,但我无法解决查看其他线程和Spring文档时遇到的问题 我将3.1.0.RELEASE与maven一起使用,并尝试使用注释和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" xml

很抱歉再次提出此类问题,但我无法解决查看其他线程和Spring文档时遇到的问题

我将3.1.0.RELEASE与maven一起使用,并尝试使用注释和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>
第二步定义我的控制器:

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-名为“WebAppServlet”的DispatcherServlet正在处理[/testSpring/]的GET请求

调试RequestMappingHandlerMapping-查找路径的处理程序方法/ 调试RequestMappingHandlerMapping-未找到[]的处理程序方法

WARN PageNotFound-在名为“WebAppServlet”的DispatcherServlet中找不到URI为[/testSpring/]的HTTP请求的映射

调试DispatcherServlet-已成功完成请求

我试图更改@RequestMapping中的参数,但它没有更改任何内容。。。我试过以下方法

@请求映射(“/*”)

@请求映射()

@请求映射(“/”)

@请求映射(“/home”)

@RequestMapping(“/home.html”)

我试图访问的url是

http://localhost:8080/testSpring/

http://localhost:8080/testSpring/home

http://localhost:8080/testSpring/home.html
你能帮我一下吗

非常感谢您的阅读


祝你今天愉快

当然,您不能进入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" />


您可以复制您的WebAppServlet吗?也许这是同样的情况?您的配置也是/*Thx很多。。。愚蠢的我:)。我想有些事情我真的不明白!我应该为应用程序上下文和DispatcherServlet上下文分别设置一个文件吗?
我应该为应用程序上下文和DispatcherServlet上下文设置一个文件吗?
这是通常的做法。
<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" />