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 ...
随机推荐
- windows程序消息机制(Winform界面更新有关)
windows程序消息机制(Winform界面更新有关) 转自:http://www.cnblogs.com/blosaa/archive/2013/05/31/3109586.html 1. Win ...
- Coolpy使用教程
---恢复内容开始--- Coolpy使用教程 1.硬件:arduino+ Ethernet Shield w5100 2.下载硬件rom,然后将rom烧进arduino. (下载地址)http:// ...
- 读取iis日志到sql server
using Fasterflect; using System; using System.Collections.Generic; using System.Data.SqlClient; usin ...
- 【WPF学习日记——[DevExpress]】GridControl 行中使用按钮
想到的办法都试了,只有这个能用,不一定是最好的,但却是自己能想到的,记录一下. <dxg:GridColumn Header="操作" Width="134&quo ...
- Basic Vlan Configure
Basic Vlan CLI Configure Switch>en Switch#conf t Enter configuration commands, one per line. End ...
- WPF-控件-编辑圆角TextBox
使用模板 代码如下: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xm ...
- vs2010的11个调试技巧和方法
调试是软件开发周期中很重要的一部分.它具有挑战性,同时也很让人疑惑和烦恼.总的来说,对于稍大一点的程序,调试是不可避免的.最近几年,调试工具的发展让很多调试任务变的越来越简单和省时. 这篇文章总结了可 ...
- centos 格式化硬盘并挂载,添加重启后生效
[root@cloud /]# passwd 更改用户 root 的密码 . 新的 密码: 重新输入新的 密码: passwd: 所有的身份验证令牌已经成功更新. [root@cloud /]# fd ...
- 【个人笔记】001-PHP基础-01-PHP快速入门-01-PHP职业路线及PHP前景
001-PHP基础-01-PHP快速入门 01-PHP职业路线及PHP前景 PHP职业路线 PHP初级工程师 1年以下 3k-6k PHP中级工程师 1-3年6k-10k PHP高级工程师 3年以上 ...
- WebAPi性能
提高WebAPi性能 前言 WebAPi作为接口请求的一种服务,当我们请求该服务时我们目标是需要快速获取该服务的数据响应,这种情况在大型项目中尤为常见,此时迫切需要提高WebAPi的响应机制,当然 ...