Spring mvc <mvc: annotation-driven/> Custom interceptor does not go, springmvc interceptor
<Mvc: annotation-driven/> This signature will register two custom interceptors. As a result, the request will go through the registered two interceptors and a bunch of defined beans.
However, this note must be defined.
Paste the Code directly.
<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 h Ttp: // 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. contr Oller "/> </context: component-scan> <! -- Parse the path of the redirection page. Prefix: prefix, suffix: suffix --> <! -- JSP view parser --> <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 "> <! -- Fix freemarker Chinese garbled characters --> <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> <! -- Interceptor --> <mvc: interceptors> <mvc: interceptor> <mvc: mapping path = "/**"/> <! -- For static resources, you can use the suffix --> <! -- <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 "/> --> <! -- You can also add exclude-mapping through folders without being intercepted by the interceptor, and the resources can be accessed normally. --> <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: mapping path ="/manage/menuBar/** "/> <bean class =" com. muke. springMVC. interceptors. managerPowerInterceptors "> </bean> </mvc: interceptor> </mvc: interceptors> </beans>
Filter out static resources by using a custom interceptor
This problem has plagued me for two days. After two days, I have rummaged through bloggers and Baidu, all kinds of nonsense, and I have also reflected on my own ways of finding problems, on the last day, I tried to find the root cause of the problem, but I still couldn't solve it.
At last, I had to ask for help. I can only say that I am not competent enough and I am wrong in thinking about the problem.
This configuration file is also available
<?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>
Both spring and spring MVC scan the @ Controller annotation, so that only one scan is performed.
I have forgotten how long it took for me to go. This label is missing from configuring the static directory, causing the @ Controller annotation to fail.