当前位置: 首页 > 知识库问答 >
问题:

在名为“[duplicate]的DispatcherServlet中找不到URI为[]的HTTP请求的映射

墨财
2023-03-14

早上,我已经检查了这个问题的大部分答案(在名为DispatcherServlet的DispatcherServlet中找不到URI为的HTTP请求的映射),以及(在名为“DispatcherServlet”的DispatcherServlet中找不到URI为[/ChickenTest/index]的HTTP请求的映射),但我仍然得到“在名为“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>

然后是我的网络。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>

我的spring配置文件

<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>

最后是我的控制器

@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));
    }

我调用"超文本传输协议://localhost:8080/bmoa-surrounds/bmoa?juan=9898",但我仍然得到没有找到HTTP请求的映射URI[/bmoa-环绕/bmoa]在DispatcherServlet与名称'bmoa',有什么想法吗?

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

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

还有这个

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'

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

共有3个答案

张高义
2023-03-14

在波姆。xml确保打包设置为warlike

徐皓君
2023-03-14

检查此配置文件:src\main\webapp\WEB-INF\spring\appServlet\controllers。xml

内容如下:

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

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

梁晋鹏
2023-03-14

我现在觉得自己很笨。。。。起初(感谢Angad提供的线索),url模式是错误的,它应该指向servlet,而且,加载的bean是BMOAServlet而不是bmoa,所以当我更改url模式时,没有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>

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));
    }

现在一切都很顺利,我还更改了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>
 类似资料: