Java 在 DispatcherServlet 中找不到名称为 ' 的带有 URI [] 的 HTTP 请求的映射

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26534071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:43:17  来源:igfitidea点击:

No mapping found for HTTP request with URI [] in DispatcherServlet with name '

javaspringspring-mvcservlets

提问by Camilo Casadiego

Morning, I already checked most of the answers to this problem (No mapping found for HTTP request with URI.... in DispatcherServlet with name) and also (No mapping found for HTTP request with URI [/ChickenTest/index] in DispatcherServlet with name 'dispatcherServlet') but I'm still getting "No mapping found for HTTP request with URI [/bmoa-surrounds/bmoa] in DispatcherServlet with name 'bmoa'", so, any help whould be apreciated:

早上,我已经检查了这个问题的大部分答案(No mapping found for HTTP request with URI .... in DispatcherServlet with name)和(No mapping found for HTTP request with URI [/ChickenTest/index] in DispatcherServlet with名称 'dispatcherServlet'),但我仍然收到“在名为 'bmoa' 的 DispatcherServlet 中找不到带有 URI [/bmoa-surrounds/bmoa] 的 HTTP 请求的映射”,因此,任何帮助都值得赞赏:

pom:

绒球:

<dependencies>
        <!-- Junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <!-- Testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>


        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>    

        <!-- Log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.6</version>
        </dependency>
        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.1</version>
        </dependency>
    </dependencies>

then my web.xml

然后我的 web.xml

<display-name>bmoa-surrounds</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/bmoa-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

     <servlet>
        <servlet-name>bmoa</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

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


    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

my spring config file

我的弹簧配置文件

<context:component-scan base-package="xxxx"/>
    <context:annotation-config/>
    <context:spring-configured/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

and finally my controller

最后是我的控制器

@Controller
public class BMOAServlet implements HttpRequestHandler {


    /**
     * 
     */
    @RequestMapping("/bmoa-surrounds/bmoa")
    public void handleRequest(final HttpServletRequest request,
            final HttpServletResponse response) throws ServletException,
            IOException {

         response.getWriter().write("result=" + handleIncomingMessage(request));
    }

I'm calling "http:// localhost :8080/bmoa-surrounds/bmoa?juan=9898" but I'm still geting No mapping found for HTTP request with URI [/bmoa-surrounds/bmoa] in DispatcherServlet with name 'bmoa', any ideas? my env is java6 a deploying to jboss

我正在调用“http://localhost :8080/bmoa-surrounds/bmoa?juan=9898”,但我仍然在 DispatcherServlet 中没有找到任何映射,URI [/bmoa-surrounds/bmoa] 的 HTTP 请求与名称 ' bmoa',有什么想法吗?我的环境是 java6 部署到 jboss

also im sure that the beans are beign loaded, I got this in the server log

我也确定豆子被加载了,我在服务器日志中得到了这个

12:34:06,671 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-5) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@57ffa0: defining beans [BMOABussinesDelegate,properties,BMOAServlet,.........]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@122d7c6

and also this

还有这个

12:34:06,753 INFO  [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa] onto handler 'BMOAServlet' 12:34:06,754 INFO  [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa.*] onto handler 'BMOAServlet' 12:34:06,755 INFO  [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-5) Mapped URL path [/bmoa-surrounds/bmoa/] onto handler 'BMOAServlet'

doesnt the last one means that the mappings are loaded?? please help ;(

最后一个不是意味着加载了映射吗??请帮忙 ;(

采纳答案by Camilo Casadiego

I'm feeling really dumb right now....at first (and thanks for the clue Angad), the url-pattern was wrong, it should point to the servlet, also, the loaded bean was BMOAServlet instead of bmoa, so when I changed the url-patter no bmoa, managed to see the error, at the end my web.xml needed to look like this:

我现在感觉真的很愚蠢……起初(感谢 Angad 提供线索),url-pattern 是错误的,它应该指向 servlet,而且,加载的 bean 是 BMOAServlet 而不是 bmoa,所以当我更改了 url-patter no bmoa,设法看到错误,最后我的 web.xml 需要看起来像这样:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/bmoa-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

     <servlet>
        <servlet-name>bmoa</servlet-name>
        <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

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


    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

and the bean class like this:

和这样的 bean 类:

@Controller("bmoa")
public class BMOAServlet implements HttpRequestHandler {



    /**
     * 
     */
    @RequestMapping("/bmoa-surrounds/bmoa")
    public void handleRequest(final HttpServletRequest request,
            final HttpServletResponse response) throws ServletException,
            IOException {

         response.getWriter().write("result=" + handleIncomingMessage(request));
    }

Now everything works smooth, I also changed the servlet class like this:

现在一切顺利,我也像这样更改了 servlet 类:

<servlet>
        <servlet-name>bmoa</servlet-name>
        <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

回答by Jerry Z.

Check this config file: src\main\webapp\WEB-INF\spring\appServlet\controllers.xml

检查这个配置文件:src\main\webapp\WEB-INF\spring\appServlet\controllers.xml

content is like:

内容是这样的:

<context:component-scan base-package="org.springframework.samples.mvc" />

is your controller in "org.springframework.samples.mvc"?

您的控制器在“org.springframework.samples.mvc”中吗?

回答by Hadi Rasouli

In pom.xml make sure packaging is set to warlike <packaging>war</packaging>,not to jar or any thing else.

在 pom.xml 中确保将包装设置为warlike <packaging>war</packaging>,而不是 jar 或其他任何东西。