本文实例讲述了spring AOP的Around增强实现方法。分享给大家供大家参考,具体如下:
一 配置
<?xml version="1.0" encoding="GBK"?><beans xmlns="http://ponent("world")public class WorldImpl implements World { // 定义一个简单方法,模拟应用中的业务逻辑方法 public void bar() { System.out.println("执行World组件的bar()方法"); }}五 测试类
package lee;import org.springframework.context.*;import org.springframework.context.support.*;import org.crazyit.app.service.*;public class BeanTest { public static void main(String[] args) { // 创建Spring容器 ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); Hello hello = ctx.getBean("hello", Hello.class); hello.foo(); hello.addUser("孙悟空", "7788"); World world = ctx.getBean("world", World.class); world.bar(); }}六 测试结果
执行目标方法之前,模拟开始事务...
执行Hello组件的foo()方法
执行目标方法之后,模拟结束事务...
执行目标方法之前,模拟开始事务...
执行Hello组件的addUser添加用户:【增加的前缀】孙悟空
执行目标方法之后,模拟结束事务...
addUser()的返回值为:400
执行目标方法之前,模拟开始事务...
执行World组件的bar()方法
执行目标方法之后,模拟结束事务...
更多关于java相关内容感兴趣的读者可查看本站专题:《Spring框架入门与进阶教程》、《Java数据结构与算法教程》、《Java操作DOM节点技巧总结》、《Java文件与目录操作技巧汇总》和《Java缓存操作技巧汇总》
希望本文所述对大家java程序设计有所帮助。