spring aop通过joinpoint传递参数
三、总结。
我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得。
三、总结。
我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得。
三、总结。
我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得。
一、概述
AOP的实现方法在上两篇博客中已经用了两种方法来实现现在的问题来了虽然我们利用AOP,那么客户端如何信息传递?利用JoinPoint接口来实现客户端给具体实现类的传递参数。
二、代码演示。
目录结构:
SecurityHandler.Java
- package com.tgb.spring;
- import org.aspectj.lang.JoinPoint;
- public class SecurityHandler{
- private void checkSecurity(JoinPoint joinPoint){
- for (int i = 0; i < joinPoint.getArgs().length; i++) {
- System.out.println(joinPoint.getArgs()[i]);
- }
- System.out.println(joinPoint.getSignature().getName());
- System.out.println("=====checkSecurity====");
- }
- }
Client.java
- package com.tgb.spring;
- import org.springframework.beans.factory.BeanFactory;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import com.tgb.spring.UserManager;
- public class Client {
- public static void main(String[] args) {
- BeanFactory factory=new ClassPathXmlApplicationContext("applicationContext.xml");
- UserManager userManager=(UserManager) factory.getBean("userManager");
- userManager.addUser("张三", "123");
- //userManager.delUser(1);
- }
- }
UserManager.java
- package com.tgb.spring;
- public interface UserManager {
- public void addUser(String username,String password);
- public void delUser(int userId);
- public String findUserById(int userId);
- public void modifyUser(int userId,String username,String password);
- }
UserManagerImpl.java
- package com.tgb.spring;
- public class UserManagerImpl implements UserManager {
- public void addUser(String username, String password) {
- //checkSecurity();
- System.out.println("===UserManager.addUser===");
- }
- public void delUser(int userId) {
- //checkSecurity();
- System.out.println("===UserManager.delUser===");
- }
- public String findUserById(int userId) {
- //checkSecurity();
- System.out.println("===UserManager.findUserById===");
- return "张三";
- }
- public void modifyUser(int userId, String username, String password) {
- //checkSecurity();
- System.out.println("===UserManager.modifyUser===");
- }
- // private void checkSecurity(){
- // System.out.println("checkSecurity");
- //
- // }
- }
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"
- xmlns:tx="http://www.springframework.org/schema/tx"
- 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.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
- <bean id="userManager" class="com.tgb.spring.UserManagerImpl" />
- <bean id="securityHandler" class="com.tgb.spring.SecurityHandler"/>
- <aop:config>
- <aop:aspect id="securityAspect" ref="securityHandler">
- <aop:pointcut id="addAddMethod" expression="execution(* com.tgb.spring.*.*(..))" />
- <aop:before method="checkSecurity" pointcut-ref="addAddMethod" />
- </aop:aspect>
- </aop:config>
- </beans>
效果图:
三、总结。
我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得。
本文转自http://blog.csdn.net/gwblue/article/details/40592117 感谢作者
spring aop通过joinpoint传递参数的更多相关文章
- spring aop 利用JoinPoint获取参数的值和方法名称
AspectJ使用org.aspectj.lang.JoinPoint接口表示目标类连接点对象,如果是环绕增强时,使用org.aspectj.lang.ProceedingJoinPoint表示连接点 ...
- Spring Aop——给Advice传递参数
给Advice传递参数 Advice除了可以接收JoinPoint(非Around Advice)或ProceedingJoinPoint(Around Advice)参数外,还可以直接接收与切入点方 ...
- Spring AOP切面的时候参数的传递
Spring AOP切面的时候参数的传递 Xml: <?xml version="1.0" encoding="UTF-8"?> <beans ...
- 菜鸟学习Spring——60s利用JoinPoint获取参数的值和方法名称
一.概述 AOP的实现方法在上两篇博客中已经用了两种方法来实现现在的问题来了虽然我们利用AOP,那么客户端如何信息传递?利用JoinPoint接口来实现客户端给具体实现类的传递参数. 二.代码演示. ...
- 使用Spring AOP预处理Controller的参数
实际编程中,可能会有这样一种情况,前台传过来的参数,我们需要一定的处理才能使用,比如有这样一个Controller @Controller public class MatchOddsControll ...
- Spring AOP中JoinPoint的用法
Spring JoinPoint的用法 JoinPoint 对象 JoinPoint对象封装了SpringAop中切面方法的信息,在切面方法中添加JoinPoint参数,就可以获取到封装了该方法信息的 ...
- Spring AOP获取方法的参数名称和参数值
aop配置: <aop:aspectj-autoproxy expose-proxy="true" /> @Before(value = "execution ...
- Spring Aop 修改目标方法参数和返回值
一.新建注解 @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Document ...
- spring aop 解决模糊查询参数 % - /等特殊符号问题
import com.hsq.common.utils.StringUtil;import org.aspectj.lang.ProceedingJoinPoint;import org.aspect ...
随机推荐
- Laravel 5 基础(一)- Laravel入门和新建项目
此系列文章是 laracasts.com 中的入门系列视频的笔记,我做了一些修改,可以参考此系列文章来学习 Laravel 5.原视频作者是 Jeffrey Way, 在此感谢.本人使用的系统是Mac ...
- DataSnap中连接池的应用
当开发人员开始创建Delphi的DataSnap应用时很常见的数据库连接定义方式是每个数据模块建立一个连接.这样做将产生大量的数据库连接,并产生很多问题.从Delphi XE开始,EMB提供了Sess ...
- protected internal修饰符
见过这样的修饰符,但是没有仔细考虑过,今天做一个小练习. 先给出一个链接,别人在网上讨论的:http://wenku.baidu.com/view/4023f65abe23482fb4da4cfe.h ...
- 系统中使用frameset和Iframe刷新页面session失效
问题:Asp.net中每次刷新页面,session中保存的只就丢失 原因: 1.有些杀毒软件会去扫描web.config文件 2.程序内部有让session丢失的代码,或服务器内存不足 3.程序有框架 ...
- 批量修改文件后缀(Python)
近期下载了很多各种教程, 但是不幸的是后缀名都是 ".mp4", 而本人喜欢 ".rmvb" 后缀,由于有轻微洁癖, 受不了后面的 ".mp4&quo ...
- 【转】Eazfuscator.NET 3.3中混淆化需要注意的一些问题
对于DLL,Eazfuscator.NET默认不会混淆化任何公共成员,因为类库的公共成员很有可能被外界调用,而对于EXE的程序集,所有类型都可能被混淆化.注意上面这句话有一个“可能”,因为Eazfus ...
- 第一个leapmotion的小游戏
自从看过leapmotion的宣传视频,就被吸引住了.觉得这东西迟早要替代鼠标,然后关注了一年多leapmotion的动态,终于在今年8月份入手了一只.//675大洋啊,心疼~ 一直想写份评测,一直想 ...
- iOS的影片播放 MediaPlayer 和 AVPlayer(转)
分类: Iphone2013-01-28 16:19 5230人阅读 评论(0) 收藏 举报 在iOS開發上,如果遇到需要播放影片,如開機動畫…,我們很習慣地會使用MediaPlayer來播放影片,因 ...
- php用户注册
前言 网站用户注册与登录是很常用的一个功能,本节教材就以此来演示一下 PHP 中如何开发用户注册与登录模块. 本节需要用到的重点 PHP 基础知识: PHP 中预定义 $_POST 和 $_GET 全 ...
- js eval()执行传参函数的写法
.cs public class Message<T> { // 数据总数 public int? Total { get; set; } // 关键数据 public List<T ...