【Java】配置拦截器 完整代码 实现拦截器功能 项目实战 打印日志输出到控制台 SpringMvc(个人梳理)
项目技术选型 spring+springmvc+maven
文章目录
前言
实现拦截器,并利用Logger打印其中的请求时间、方法、和请求url
一、配置拦截器参数spring-servlet.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"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.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 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
<context:component-scan base-package="com.自己的包名.training.*" />
<mvc:annotation-driven />
<aop:aspectj-autoproxy/>
<!-- 视图解析 -->
<mvc:view-resolvers>
<mvc:jsp cache-views="false" prefix="/WEB-INF/jsp/" suffix=".jsp" />
</mvc:view-resolvers>
<!--@Aysnc异步-->
<!