我正在使用spring mvc进行一些演示,部署应用程序时遇到问题。我使用的是wildfly 10.0.0
不明白发生了什么
在我的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>
<?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/>
和我的控制器
@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");
}
}
部署应用程序时,控制台上会显示以下错误
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'
答案 0 :(得分:0)
看起来可能是你的控制器没有弹簧应用程序扫描。如您所定义:
<context:component-scan base-package="com.cmac.simu" />
所以你的控制器必须在com.cmac.simu
包内。所以spring配置可以扫描你的控制器。