在Eclipse IDE中没有GET / web-customer-tracker / customer / list的映射[关闭]

问题描述 投票:0回答:1

[这里,我的问题是在控制器中的请求映射已完成,但是在http://localhost:8080/web-customer-tracker/customer/list上运行代码时,出现的错误是org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告:GET / web-customer-tracker / customer / list

没有映射

[请在这里帮助我解决它,我已经上传了控制器和web.xml代码段。

这是CustomerController代码段

package Controllers;

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

@Controller
@RequestMapping("/customer")
public class CustomerController {

    @RequestMapping("/list")
    public String listCustomers(Model theModel) {
        return "list-customers";
    }
}

这是web.xml代码段

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>spring-mvc-crud-demo</display-name>

  <absolute-ordering />

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

  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring-mvc-crud-demo-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>
java spring spring-mvc web.xml request-mapping
1个回答
0
投票

您是否设置了上下文路径?如果没有,则在application.properties文件中添加以下属性。server.servlet.contextPath=/web-customer-tracker

或如下设置环境变量Set SERVER_SERVLET_CONTEXT_PATH=/web-customer-tracker

按照下面的路径。http://zetcode.com/springboot/contextpath/

© www.soinside.com 2019 - 2024. All rights reserved.