[这里,我的问题是在控制器中的请求映射已完成,但是在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>
您是否设置了上下文路径?如果没有,则在application.properties文件中添加以下属性。server.servlet.contextPath=/web-customer-tracker
或如下设置环境变量Set SERVER_SERVLET_CONTEXT_PATH=/web-customer-tracker