<mvc:annotation-driven/> 这个便签会注册2个自定义拦截器,所以导致请求过来就会自己去走注册的这2个拦截器和定义的一堆bean
但是这个便签是必须得定义的
直接贴代码吧
<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.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd "> <mvc:default-servlet-handler/> <mvc:annotation-driven/> <context:component-scan base-package="com.muke.controller" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- 对转向页面的路径解析。prefix:前缀, suffix:后缀 --> <!--JSP视图解析器--> <bean id="viewResolverJsp" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"/> <property name="suffix" value=".jsp"/> </bean> <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="/WEB-INF/freemarker"/> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <!-- 解决freemarker中文乱码 --> <property name="contentType" value="text/html;charset=UTF-8"/> <property name="cache" value="true"/> <property name="prefix" value=""/> <property name="suffix" value=".ftl"/> <property name="order" value="0"/> </bean> <!-- 拦截器 --> <mvc:interceptors> <mvc:interceptor > <mvc:mapping path="/**"/> <!--对于静态资源,可以通过后缀名--> <!--<mvc:exclude-mapping path="/**/*.js"/> <mvc:exclude-mapping path="/**/*.css"/> <mvc:exclude-mapping path="/**/*.jpg"/> <mvc:exclude-mapping path="/**/*.gif"/> <mvc:exclude-mapping path="/**/*.png"/>--> <!--也可以通过文件夹, 加这些exclude-mapping就不会被拦截器拦截到,资源能够正常访问--> <mvc:exclude-mapping path="/html/**"/> <mvc:exclude-mapping path="/back_css/**"/> <mvc:exclude-mapping path="/back_js/**"/> <mvc:exclude-mapping path="/back_img/**"/> <mvc:exclude-mapping path="/back_other/**"/> <mvc:exclude-mapping path="/layer/**"/> <mvc:exclude-mapping path="/laypage/**"/> <bean class="com.muke.springMVC.interceptors.DefaultInterceptors"/> </mvc:interceptor> <mvc:interceptor> <mvc:mapping path="/manage/menuBar/**"/> <bean class="com.muke.springMVC.interceptors.ManagerPowerInterceptors"></bean> </mvc:interceptor> </mvc:interceptors> </beans>
通过自定义拦截器来过滤掉静态资源
这个问题困扰了我2天,整整熬了2天,翻遍了博客员和百度,各种瞎扯淡,也反思了自己找问题的方式,最后一天自己尝试着去寻找问题的根源,但还是解决不了
最后只能求救我师傅解决了。只能说自己功力不够和思考问题的方向错了吧
还要有这个配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> <context:component-scan base-package="com.muke" use-default-filters="false"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> </beans>
spring 和spring MVC都会扫描@Controller这个注解,这样就只扫描一次了
已经忘记这个坑我走了多久了。从配置静态目录,少了这个这个标签导致@Controller这个注解没生效,到现在,唉真坑
时间: 2024-10-09 19:41:33