: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find 我的拦截器名称。
在spring.xml中没有报错。整个项目也没有红色的❌,但就是一运行tomcat就出现拦截器类找不到。
我的拦截器类定义:
public class MyInterceptor implements HandlerInterceptor{
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
System.out.println("指定拦截器:MyInterceptor1...preHandle");
return true;
}
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
System.out.println("指定拦截器:M有Interceptor..postHandle");
}
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception {
System.out.println("指定拦截器:MyInterceptor1..afterCompletion");
}
}
只是简单地实现了一个HandlerInterceptor接口里面的三个方法。
我的springweb.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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
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.3.xsd">
<context:component-scan base-package="cn.javaee.springmvc.controller"/>
<mvc:interceptors>
<bean class="cn.javaee.springmvc.interceptor.UserInterceptor"/>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<mvc:exclude-mapping path="/hello1"/>
<bean class="cn.javaee.springmvc.interceptor.MyInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
</beans>
开始的时候我的报名是以springmvc开头的,也就是:
springmvc.interceptor和springmvc.controller这种。然后我的项目:
<modelVersion>4.0.0</modelVersion>
<groupId>cn.javaee</groupId>
<artifactId>ch7-1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<spring.version>5.1.6.RELEASE</spring.version>
</properties>
是这样的。也就是说我的报名并没有带上groupId。当我尝试修改包名,即从springmvc.interceptor改为了cn.javaee.springmvc.interceptor等,加入了groupId前缀在报名前面,并对应修改了spring.xml文件。报错消失。。。。