Purview接口
package aop; public interface Purview { void checkLogin(); }
Purview接口的实现类PurviesImpl.java
package aop; public class PurviewImpl implements Purview { public void checkLogin() { System.out.println("This is checkLogin method!"); } }
拦截器类PurviewAdvice.java
package aop; import java.lang.reflect.Method; import org.springframework.aop.MethodBeforeAdvice; public class PurviewAdvice implements MethodBeforeAdvice { public void before(Method arg0, Object[] arg1, Object arg2) throws Throwable { System.out.println("This is before method!"); } }
测试类Test.java
package aop; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test { public static void main(String[] args) { // TODO 自动生成方法存根 ApplicationContext ctx = new ClassPathXmlApplicationContext( "aop/applicationContext.xml"); Purview purview = (Purview) ctx.getBean("purviewImpl"); purview.checkLogin(); } }
配置文件applicationContext.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:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" default-autowire="autodetect"> <bean id="purviewImpl" class="aop.PurviewImpl"></bean> <bean id="purviewAdvice" class="aop.PurviewAdvice"></bean> <bean id="purviewAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <property name="advice"> <ref local="purviewAdvice" /> </property> <property name="patterns"> <list> <value>.*checkLogin.*</value> </list> </property> </bean> <bean id="autoproxyaop" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <value>purviewImpl</value> </property> <property name="interceptorNames"> <list> <value>purviewAdvisor</value> </list> </property> </bean> </beans>
运行结果:
This is before method! This is checkLogin method!
文章来源:http://blog.csdn.net/yirentianran/article/details/3380529
相关推荐
NULL 博文链接:https://lpm528.iteye.com/blog/1259187
spring拦截器的简单例子.docx
拦截器是Spring MVC中一个十分重要且应用广泛的内容。这里简单敲了一个简单的例子,简单易懂
idea软件。SpringBoot的拦截器的博客所写的例子。preHandle()方法的返回值true和false的详细区别还未描述
1.针对SpringMVC注解的配置,可起到入门的作用 2.Spring+JdbcTemplate事物管理 3.Spring+Hibernate事物管理 4.Spring实现DWR注解方式的应用配置 ...6.Spring通过拦截器实现防止重复提交实例 对学习,会起到非常好的效果
这里少了一个类,是根据实体类生成xml的文件下载地址为:http://download.csdn.net/detail/qq_14996421/9495688
JavaWeb项目,SpringMVCHibernate实例【含登录拦截器例子】
SpringMVC拦截器例子详解,
struts2+spring4+mybatis3,登录jquery ajax,struts拦截器,springAOP的例子。带部分注释。
本篇文章主要介绍了使用spring拦截器实现日志管理实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
非常简单的aop例子,可以从该离子出发隐身出很多其他的问题的思考。
拦截器spring mvc,非常经典,非常容易理解,结合例子。官方推荐
主要介绍了spring boot的拦截器简单使用实例代码,需要的的朋友参考下吧
主要介绍了Spring Boot拦截器和过滤器实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Spring_AOP四种创建通知(拦截器)类型,介绍的比较详细,有实例
主要介绍了spring设置拦截器代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Spring Security 3.1.3配置实例
主要介绍了spring boot配置拦截器代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
主要介绍了Spring Boot编写拦截器教程实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下