- 浏览: 697118 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (260)
- web 开发 (44)
- struts (14)
- java (39)
- 我的感受 (2)
- ajax (2)
- spring (22)
- Hibernate (4)
- struts2 (1)
- java 面试题 (1)
- 英语 学习类 (2)
- jdk1.6特性 (1)
- extjs (13)
- oracle (3)
- JQuery (3)
- ┠ 『Spring 3.0』 ┨ (1)
- 『LOG4J』 (2)
- 『常用数据』 (1)
- JavaMail (0)
- 〓『 EJB3.0 』〓 (0)
- HTML5 (5)
- Canvas (0)
- spring2.5 (0)
- HPH 5 (1)
- C# .net (0)
- UML (1)
- REST (2)
- JS_validate (1)
- 项目管理文章 (1)
- 闲聊闲记 (12)
- SQL-SQL (3)
- javascript (18)
- js (4)
- linux (8)
- 电子政务 (1)
- 项目对象模型 (1)
- 系统集成项目管理 (1)
- shell (2)
- mysql (1)
- solr (5)
- cxf;services (2)
- 11 (0)
- 缓存 (1)
- cached (3)
- 单片机通信 (1)
- cached;oscache (1)
- android (15)
- android;蓝牙 (1)
- Lucene (5)
- TTS (1)
- 网络爬虫 (1)
- HtmlCleaner (1)
- iPhone (2)
- 有感而发 (1)
- Python (0)
- jetty (1)
- Redis (1)
- hadoop (1)
- socket (1)
- 色彩顾问 (1)
- javaapns (1)
- bat (1)
- object-c (4)
- ios (4)
- C-学习 (1)
- 搜索 (1)
- c# (1)
最新评论
-
annie211:
Angularjs构建一个CRUD应用可能用到的全部内容包括:数据绑定、基本模板标识符、表单验证、路由、深度链接、组件重用、依赖注入 -
潇寒听竹:
你好,请问您上传的那个APK为什么每次只能识别一次,不能连续识 ...
pocketsphinxAdroid离线语音识别---入门 -
ichenwenjin:
Angularjs构建一个CRUD应用可能用到的全部内容包括:数据绑定、基本模板标识符、表单验证、路由、深度链接、组件重用、依赖注入 -
NN_iaoiao:
问一下 你的这个People 类 是自定义的还是android ...
android 获取电话本中的联系人列表 -
wangzhe_real:
对于刚接触的我是一个很详细的教程,太感谢了
JAX-RS cxf web服务 rest简单增删改查 集成spring webService
(1)前置通知
接口:org.springframework.aop.MethodBeforeAdvice
使用前置通知可以在联结点执行前进行自定义的操作。不过,Spring里只有一种联结点,即方法调用,所以前置通知事实上就是让你能在方法调用前进行一些操作。前置通知可以访问调用的目标方法,也可以对该方法的参数进行操作,不过它不能影响方法调用本身。
示例:
IHello接口
public interface IHello { public void hello(String name); } |
IHello接口实现
public class HelloSpeaker implements IHello { public void hello(String name) { System.out.println("Hello, " + name); } } |
IHello实现代理
public class LogBeforeAdvice implements MethodBeforeAdvice { private Logger logger = Logger.getLogger(this.getClass().getName());
public void before(Method method, Object[] args, Object target) throws Throwable { logger.log(Level.INFO, "method starts..." + method); } } |
Spring配置文件
<bean id="logBeforeAdvice" class="onlyfun.caterpillar.LogBeforeAdvice"/>
<bean id="helloSpeaker" class="onlyfun.caterpillar.HelloSpeaker"/>
<bean id="helloProxy" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces"> <value>onlyfun.caterpillar.IHello</value> </property> <property name="target"> <ref bean="helloSpeaker"/> </property> <property name="interceptorNames"> <list> <value>logBeforeAdvice</value> </list> </property> </bean> |
测试类
public class SpringAOPDemo { public static void main(String[] args) { ApplicationContext context = new FileSystemXmlApplicationContext( "beans-config.xml"); IHello helloProxy = (IHello) context.getBean("helloProxy"); helloProxy.hello("Justin"); } } |
(2)后置通知(或返回后通知)
接口:org.springframework.aop.AfterReturningAdvice
后置通知在联结点处的方法调用已经完成,并且已经返回一个值时运行,后置通知可以访问调用的目标方法,以及该方法的参数和返回值。因为等到通知执行时该方法已经调用,后置通知完全不能影响方法调用本身。
示例:
IHello接口
public interface IHello { public void hello(String name); } |
IHello接口实现
public class HelloSpeaker implements IHello { public void hello(String name) { System.out.println("Hello, " + name); } } |
IHello实现代理
public class LogAfterAdvice implements AfterReturningAdvice { private Logger logger = Logger.getLogger(this.getClass().getName());
public void afterReturning(Object object, Method method, Object[] args, Object target) throws Throwable { logger.log(Level.INFO, "method ends..." + method); } } |
Spring配置文件
<bean id="logAfterAdvice" class="onlyfun.caterpillar.LogAfterAdvice"/>
<bean id="helloSpeaker" class="onlyfun.caterpillar.HelloSpeaker"/>
<bean id="helloProxy" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces"> <value>onlyfun.caterpillar.IHello</value> </property> <property name="target"> <ref bean="helloSpeaker"/> </property> <property name="interceptorNames"> <list> <value>logAfterAdvice</value> </list> </property> </bean> |
测试类
public class SpringAOPDemo { public static void main(String[] args) { ApplicationContext context = new FileSystemXmlApplicationContext( "beans-config.xml"); IHello helloProxy = (IHello) context.getBean("helloProxy"); helloProxy.hello("Justin"); } } |
(3)包围通知
接口:org.aopalliance.intercept.MethodInterceptor
Spring中的包围通知模AOP联盟的“方法拦截器”标准。包围通知可以在目标方法之前和之后动行,我们也可以定义在什么时候调用目标方法。如果需要,我们也可以另写自己的逻辑而完全不调用目标方法。
示例:
IHello接口
public interface IHello { public void hello(String name); } |
IHello接口实现
public class HelloSpeaker implements IHello { public void hello(String name) { System.out.println("Hello, " + name); } } |
IHello实现代理
public class LogInterceptor implements MethodInterceptor { private Logger logger = Logger.getLogger(this.getClass().getName());
public Object invoke(MethodInvocation methodInvocation) throws Throwable { logger.log(Level.INFO, "method starts..." + methodInvocation.getMethod());
Object result = null; try { result = methodInvocation.proceed(); } finally { logger.log(Level.INFO, "method ends..." + methodInvocation.getMethod() + "\n"); } return result; } |
Spring配置文件
<bean id="logInterceptor" class="onlyfun.caterpillar.LogInterceptor"/>
<bean id="helloSpeaker" class="onlyfun.caterpillar.HelloSpeaker"/>
<bean id="helloProxy" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces"> <value>onlyfun.caterpillar.IHello</value> </property> <property name="target"> <ref bean="helloSpeaker"/> </property> <property name="interceptorNames"> <list> <value>logInterceptor</value> </list> </property> </bean> |
测试类
public class SpringAOPDemo { public static void main(String[] args) { ApplicationContext context = new FileSystemXmlApplicationContext( "beans-config.xml"); IHello helloProxy = (IHello) context.getBean("helloProxy"); helloProxy.hello("Justin"); } |
发表评论
-
Java 数据验证
2017-05-12 10:27 1069在web开发当前就会遇到一些数据有效性验证的相关代码编 ... -
spring mvc rest 小例子
2012-05-24 15:35 1802http://localhost:8080/mainrest/ ... -
JAX-RS cxf web服务 rest简单增删改查 集成spring webService
2011-09-14 14:35 5725没时间什么也不多说了。所有的话都在代码里。 ... -
aop svn
2010-11-30 08:31 972aop http://student.csdn.net/sp ... -
spring 2.5 mvc 注解 ajax 实现
2010-03-07 19:30 4220spring 2.5 的mvc 大量的使用了注解,减少了xml ... -
spring 2.5 注释驱动的IOC功能
2010-03-04 04:18 1524spring 注释功相当于 以前在spring的配置文件的b ... -
spring 2.0_MVC+Ibatis web 实例
2010-03-04 01:50 2567这个便子是我在面试之后回来做的, 前段时间不久,我去面 ... -
spring 2.0 配置文 件头
2010-02-28 00:02 129<?xml version="1.0" ... -
Spring Jar包详解
2010-01-28 13:35 1275摘自:http://vc88.iteye.com/ ... -
spring配置事务
2010-01-27 17:38 1946<?xml version="1.0" ... -
SSH(Spring+Struts+Hibernate)综合应用
2009-08-04 23:56 1474(1)Struts与Spring整合 <1> 在 ... -
spring 事务管理
2009-08-04 23:31 1629对于J2EE 应用程序而言,事务的处理一般有两种模式: ... -
在Spring应用中使用Hibernate
2009-08-04 11:56 1009<1>Spring in Hibernate示例 ... -
JDBC操作的Java对象化
2009-08-03 23:41 133org.springframework.jdbc.object ... -
基于Spring的数据访问
2009-08-03 22:52 1060(1)在Spring应用中使用JDBC Spring对JDB ... -
Spring的体系结构
2009-08-03 16:42 3836Spring 框架是一个分层架 ... -
Spring bean的封装机制
2009-08-03 16:31 1687Spring 从核心而言,是一个DI 容器,其设计哲学是提供一 ... -
spring 中 Bean继承
2009-08-03 16:29 2003某些情况下,你也许需要定义多个实现了共用接口的相同类型的bea ... -
spring 中自动装配你的Bean
2009-08-03 16:27 1852如果你不喜欢自己将你的程序装配起来,你可以尝试让Spring自 ... -
spring 注入参数(Injection Parameters)
2009-08-03 16:25 3007(1)简单的值注入 将简单的值注入到beans里面是很简单的 ...
相关推荐
6.8.1. 在Spring中使用AspectJ进行domain object的依赖注入 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7...
这是一种常用的AOP通知类型,常用于日志记录、安全性检查等方面。 下面详细解释如何在Spring Boot中使用@Before注解,并提供一个完整的实例和代码来演示其用法。在实例中,我们将创建一个简单的用户认证功能,并在...
13.8 使用Spring的常用测试注解 540 13.8.1 问题 540 13.8.2 解决方案 540 13.8.3 工作原理 541 13.9 小结 542 第14章 Spring Portlet MVC框架 544 14.1 用Spring Portlet MVC开发一个简单的Portlet ...
13.8 使用Spring的常用测试注解 540 13.8.1 问题 540 13.8.2 解决方案 540 13.8.3 工作原理 541 13.9 小结 542 第14章 Spring Portlet MVC框架 544 14.1 用Spring Portlet MVC开发一个简单的Portlet ...
6.8.1. 在Spring中使用AspectJ进行domain object的依赖注入 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7...
在 Java EE 设计模式中,常用的设计模式有: 1.Singleton Pattern:单例模式,确保某个类只有一个实例,并提供一个全局访问点。 在 Spring 中,singleton scope 是默认的 scopes,表示 Bean 只会被实例化一次,...
Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中涉及的配置管理、服务发现、断路器、智能路由、微代理、控制总线、全局锁、决策竞选、分布式会话和集群状态管理等操作提供了一种...
Spring 中常用的设计模式达到九种,我们举例说明: 工厂模式(Factory Method)通常由应用程序直接使用 new 创建新的对象,为了将对象的创建和使用相分离,采用工厂模式,即应用程序将对象的创建及初始化职责交给...
用户会员中心:SVIP与VIP,定时任务/RabbitMQ延迟队列/登录验证三种判定会员截止时间到期用邮箱去提醒 用户支付中心:我的钱包和支付宝支付以及打印我的账单,内网穿透获得异步通知作为结果判定标志,原始支付的普通...
1.什么是Spring框架 2.Spring的特点 3.什么是IOC ...13.AOP常用的术语 14.什么是AspectJ框架 15.AspectJ常见通知类型 16.AspectJ 的切入点表达式(掌握) 17.AspectJ的前置通知@Before .... .... ....
10. 认识Spring AOP中底层常用的一些核心类 11. 源码阅读之查找aop相关的BeanDefinitionParser流程课程目标 1. 了解什么是AOP? 2. 了解AOP能干什么? 3. 了解AOP都有哪些实现? 4. 掌握AOP核心概念(通知、切入点、...
总的来说,@Pointcut注解是Spring Boot AOP中非常有用的一部分,它允许我们轻松地定义切点并应用通知来实现面向切面编程。通过这种方式,我们可以有效地在应用程序中实现横切关注点的功能,提高代码的可维护性和重用...
4. 注解部分列举了常用的Spring注解及其作用,如@Component、@Autowired等。 5. 数据访问部分涉及了Spring对JDBC、Hibernate等数据访问技术的集成支持。 6. AOP部分对面向切面的核心概念如通知、连接点、切点等进行...
用spring AOP(包括几种常用的通知类型)做的小程序
- 后端采用Spring Boot、Spring Security、Redis & Jwt。 - 权限认证使用Jwt,支持多终端认证系统。 - 支持加载动态权限菜单,多方式轻松权限控制。 - 高效率开发,使用代码生成器可以一键生成前后端代码。 ## 功能...
- 后端采用Spring Boot、Spring Security、Redis & Jwt。 - 权限认证使用Jwt,支持多终端认证系统。 - 支持加载动态权限菜单,多方式轻松权限控制。 内置功能 1. 用户管理:用户是系统操作者,该功能主要完成系统...
Spring AOP 常用于日志记录,性能统计,安全控制,事务处理,异常处理等等,本项目对其常用语法进行示例。
模块简介 基于 IJPay 让支付触手可及,封装了微信支付、支付宝支付常用的支付方式以及各种常用的接口,提供渠道管理、订单管理、商品订单、回调管理等功能 协同办公工作流 模块简介 基于activiti 最经典版本5.22 ...
后端采用Spring Boot、Spring Security、Redis & Jwt。 权限认证使用Jwt,支持多终端认证系统。 支持加载动态权限菜单,多方式轻松权限控制。 高效率开发,使用代码生成器可以一键生成前后端代码。 内置功能 用户...
多态的好处,代码中如何实现多态 ...Spring中有哪些类型的通知(Advice)? Spring Boot 的核心配置文件有哪几个?它们的区别是什么? springboot集成mybatis的过程 springcloud如何实现服务的注册和发现