[英]No mapping found for HTTP Spring MVC
I'm doing a little demo with spring mvc and I have a problem when deploying the application. 我正在用spring mvc做一些演示,在部署应用程序时遇到问题。 I'm using wildfly 10.0.0 我正在使用wildfly 10.0.0
In don't understand what is happening 在不了解发生了什么
in My web.xml 在我的web.xml中
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>simu-cmac</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/app-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>simu-cmac</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
in my app-config.xml 在我的app-config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
<context:component-scan base-package="com.cmac.simu" />
<mvc:annotation-driven/>
And my Controller 还有我的控制器
@Controller
public class SimuAPIController {
protected final Log logger = LogFactory.getLog(getClass());
@RequestMapping("/home.htm")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
logger.info("Returning home view");
System.out.println("To home view");
return new ModelAndView("home.jsp");
}
}
When the application is deployed the following error is displayed on the console 部署应用程序后,控制台上将显示以下错误
19:50:39,417 WARN [org.springframework.web.servlet.PageNotFound] (default task-3) No mapping found for HTTP request with URI [/simu-cmac/home.htm] in DispatcherServlet with name 'simu-cmac'
It seems may be your controller is not scaned by spring application. 看来您的控制器没有被Spring应用程序扫描。 As you defined : 如您所定义:
<context:component-scan base-package="com.cmac.simu" />
So your controller must be inside com.cmac.simu
package. 因此,您的控制器必须位于com.cmac.simu
软件包中。 So spring config can scan your controller. 因此spring config可以扫描您的控制器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.