三、总结。

我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得。

三、总结。

我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得。

三、总结。

我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得。

一、概述

AOP的实现方法在上两篇博客中已经用了两种方法来实现现在的问题来了虽然我们利用AOP,那么客户端如何信息传递?利用JoinPoint接口来实现客户端给具体实现类的传递参数。

二、代码演示。

目录结构:

SecurityHandler.Java

  1. package com.tgb.spring;
  2. import org.aspectj.lang.JoinPoint;
  3. public class SecurityHandler{
  4. private void checkSecurity(JoinPoint joinPoint){
  5. for (int i = 0; i < joinPoint.getArgs().length; i++) {
  6. System.out.println(joinPoint.getArgs()[i]);
  7. }
  8. System.out.println(joinPoint.getSignature().getName());
  9. System.out.println("=====checkSecurity====");
  10. }
  11. }

Client.java

  1. package com.tgb.spring;
  2. import org.springframework.beans.factory.BeanFactory;
  3. import org.springframework.context.support.ClassPathXmlApplicationContext;
  4. import com.tgb.spring.UserManager;
  5. public class Client {
  6. public static void main(String[] args) {
  7. BeanFactory factory=new ClassPathXmlApplicationContext("applicationContext.xml");
  8. UserManager userManager=(UserManager) factory.getBean("userManager");
  9. userManager.addUser("张三", "123");
  10. //userManager.delUser(1);
  11. }
  12. }

UserManager.java

  1. package com.tgb.spring;
  2. public interface UserManager {
  3. public void addUser(String username,String password);
  4. public void delUser(int userId);
  5. public String findUserById(int userId);
  6. public void modifyUser(int userId,String username,String password);
  7. }

UserManagerImpl.java

  1. package com.tgb.spring;
  2. public class UserManagerImpl implements UserManager {
  3. public void addUser(String username, String password) {
  4. //checkSecurity();
  5. System.out.println("===UserManager.addUser===");
  6. }
  7. public void delUser(int userId) {
  8. //checkSecurity();
  9. System.out.println("===UserManager.delUser===");
  10. }
  11. public String findUserById(int userId) {
  12. //checkSecurity();
  13. System.out.println("===UserManager.findUserById===");
  14. return  "张三";
  15. }
  16. public void modifyUser(int userId, String username, String password) {
  17. //checkSecurity();
  18. System.out.println("===UserManager.modifyUser===");
  19. }
  20. //  private void checkSecurity(){
  21. //      System.out.println("checkSecurity");
  22. //
  23. //  }
  24. }

applicationContext.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:aop="http://www.springframework.org/schema/aop"
  5. xmlns:tx="http://www.springframework.org/schema/tx"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  7. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
  8. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
  9. <bean id="userManager" class="com.tgb.spring.UserManagerImpl" />
  10. <bean id="securityHandler" class="com.tgb.spring.SecurityHandler"/>
  11. <aop:config>
  12. <aop:aspect id="securityAspect" ref="securityHandler">
  13. <aop:pointcut id="addAddMethod" expression="execution(* com.tgb.spring.*.*(..))" />
  14. <aop:before method="checkSecurity" pointcut-ref="addAddMethod" />
  15. </aop:aspect>
  16. </aop:config>
  17. </beans>

效果图:

三、总结。

我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得。

本文转自http://blog.csdn.net/gwblue/article/details/40592117 感谢作者

spring aop通过joinpoint传递参数的更多相关文章

  1. spring aop 利用JoinPoint获取参数的值和方法名称

    AspectJ使用org.aspectj.lang.JoinPoint接口表示目标类连接点对象,如果是环绕增强时,使用org.aspectj.lang.ProceedingJoinPoint表示连接点 ...

  2. Spring Aop——给Advice传递参数

    给Advice传递参数 Advice除了可以接收JoinPoint(非Around Advice)或ProceedingJoinPoint(Around Advice)参数外,还可以直接接收与切入点方 ...

  3. Spring AOP切面的时候参数的传递

    Spring AOP切面的时候参数的传递 Xml: <?xml version="1.0" encoding="UTF-8"?> <beans ...

  4. 菜鸟学习Spring——60s利用JoinPoint获取参数的值和方法名称

    一.概述 AOP的实现方法在上两篇博客中已经用了两种方法来实现现在的问题来了虽然我们利用AOP,那么客户端如何信息传递?利用JoinPoint接口来实现客户端给具体实现类的传递参数. 二.代码演示. ...

  5. 使用Spring AOP预处理Controller的参数

    实际编程中,可能会有这样一种情况,前台传过来的参数,我们需要一定的处理才能使用,比如有这样一个Controller @Controller public class MatchOddsControll ...

  6. Spring AOP中JoinPoint的用法

    Spring JoinPoint的用法 JoinPoint 对象 JoinPoint对象封装了SpringAop中切面方法的信息,在切面方法中添加JoinPoint参数,就可以获取到封装了该方法信息的 ...

  7. Spring AOP获取方法的参数名称和参数值

    aop配置: <aop:aspectj-autoproxy expose-proxy="true" /> @Before(value = "execution ...

  8. Spring Aop 修改目标方法参数和返回值

    一.新建注解 @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Document ...

  9. spring aop 解决模糊查询参数 % - /等特殊符号问题

    import com.hsq.common.utils.StringUtil;import org.aspectj.lang.ProceedingJoinPoint;import org.aspect ...

随机推荐

  1. 七天学会NodeJS-学习笔记

    在网上发现一篇nodeJS教程,名为七天学会NodeJS,标题很有吸引力.我不指望七天能学会,只希望可以入门,下面是我的学习笔记和遇到的问题. 教程网址:http://nqdeng.github.io ...

  2. nodejs ssh2

    https://www.npmjs.com/package/ssh2 npm install ssh2  ssh2文件下载: //前台命令下发 app.get('/test/fileDownload' ...

  3. Application,Session和Cookie

    做ASP.NET,肯定会和这几个对象打交道,这些也是基础面试的常见题目,总结一下还是必要的,好在大神已经总结好了,直接参考就好了: http://www.cnblogs.com/breezeblew/ ...

  4. 第25章 项目6:使用CGI进行远程编辑

    初次实现 25-1 simple_edit.cgi --简单的网页编辑器 #!D:\Program Files\python27\python.exeimport cgiform = cgi.Fiel ...

  5. SQL Server Management Studio Keyboard shortcuts

    一些平时在SQL Server Management Studio 使用到的快捷键 F5 (Ctrl+x)执行选中部分的语句,没有选中则全文执行 Ctrl+L 现实执行计划(估计) Ctrl+M 在运 ...

  6. OBIEE 11g:Error:nQSError 36010 Server version 318 cannot read the newer version of the repository

    biee11g升级到最新版以后,发现了一些bug,需要回退到原来的版本,卸载掉升级包以后,启动BI服务,会报上述错误.这是因为资料库文件已经升级为了最新版本.这时候我们需要将资料库文件进行降版本操作. ...

  7. LINQ.CS

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Zdso ...

  8. user-agent中的mozilla

    ie说我等不急了,所以user-agent增加 mozilla标识 这篇文章极其好玩:http://nonfu.me/p/8262.html

  9. Asp.Net生命周期系列五

    如果您看了我的前四篇文章,应该知道目前Http请求已经流到了HttpModule这个程序员手中了,而且我们可以注册自己的HttpModule并且可以在里面注册一些事件来控制这个Http请求,但是到目前 ...

  10. Linux内核分析作业一

    一.实验 通过反汇编一个简单的c语言程序来分析计算机是如何工作的 1.进入实验楼,在实验楼环境下把c语言代码转换成汇编码 汇编代码如下图: 二.汇编代码的工作过程中堆栈的变化:(手绘步骤,顺序是从左到 ...