gpt4 book ai didi

java - 警告 : No mapping found for HTTP request with URI [] in DispatcherServlet with name 'dispatcher'

转载 作者:行者123 更新时间:2023-11-28 23:26:52 28 4
gpt4 key购买 nike

<分区>

我刚刚开始实现简单的 Spring REST api 应用程序。我的 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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">


<display-name>Archetype Created Web Application</display-name>

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

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

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

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

这是我的 dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:component-scan base-package="com.suntravel.service.controller" />

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

这是我的 SunTravelController.java 类。

package com.suntravel.service.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/suntravel")
public class SunTravelController
{
@RequestMapping(value = "/{name}", method = RequestMethod.GET, produces = "application/json")
public String getHotelList( @PathVariable String name )
{
return name;

}

}

然后我将其部署在 tomcat 服务器中并尝试访问 http://localhost:8080/SpringRestServer/suntravel?Bob

然后我在控制台日志中收到以下错误。

WARNING: No mapping found for HTTP request with URI [/SpringRestServer/suntravel] in DispatcherServlet with name 'dispatcher'

项目结构

enter image description here

如有任何帮助,我们将不胜感激。

谢谢

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com