标签:val csdn com mapping extc code source div inf
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
将组件扫描<context:component-scan base-package="*"/>
将扫描全部改到扫描具体的包下
不断导入jar包,错误又是不同的
其他人链接:https://blog.csdn.net/m0_37927008/article/details/78288509
无非几种情况 1、controller没被扫描注册到 2、RequestMaping 的映射地址写错 3、映射后缀的问题
这是我的Controller
No mapping 就是映射问题,我写的是
@RequestMapping("./login.do")报错,将./去掉编译成功,成功跳到jsp
junit不断取组件值,确认是否被扫描到,Contoller组件是扫描到,可以获取到,然后再确认HandlerMapping是否配置
@Test public void test() { ApplicationContext ac=new ClassPathXmlApplicationContext("./spring-mvc.xml"); LoginController lc=ac.getBean("loginController",LoginController.class); System.out.print(lc); }
spring-mvc.xml
<!-- 配置HandlerMapping 开启注解配置 --> <!-- 配置mvc标注扫描 --> <mvc:annotation-driven/> <!-- 开启组件扫描 --> <context:component-scan base-package="com.tracy.*"></context:component-scan> <!-- 配置ViewResolver --> <bean id="ModelAndView" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"></property> <property name="suffix" value=".jsp"></property> </bean>
LoginController
@Controller public class LoginController { @RequestMapping("login.do") public String execute1() { return "login"; } }
<?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" version="3.0"> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app>
SpringMVC组件扫描,HandlerMapping配置,servlet配置过程出错
标签:val csdn com mapping extc code source div inf
原文地址:https://www.cnblogs.com/tracyDemo/p/13227928.html