Spring动态代理配置文件---切入点表达式

学习目标:切入点表达式


学习内容:

<aop:config>
   <!--定义切入点-->
   <aop:pointcut id="pc" expression="execution(* *(..))"/> 
</aop:config>

一、方法切入点表达式 
   1、 * *(..)---->所有方法

                *  访问修饰符  返回值类型      *代表所有

                *  方法名  

              ()形参列表

                 ..   对于方法的形参没有要求,表示所有

        2、定义login方法作为切入点

                *  login(..)------>配置文件中定义的所有类的login方法都会切入

        3、定义regist方法作为切入点

                *  regist(..)------>配置文件中定义的所有类的regist方法都会切入

        4、定义login方法且login方法有两个字符串类型的参数  作为切入点

                *  login(String,String)

        5、定义login方法且lo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,以下是一个示例配置文件 applicationContext.xml,其中配置了切入点通知器和切面,实现了在目标对象的相应方法中添加相应的代码: ```xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 目标对象 --> <bean id="targetObject" class="com.example.TargetObject"/> <!-- 切入点通知器 --> <bean id="pointcutAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <property name="pattern" value="com.example.TargetObject.*"/> <property name="advice"> <bean class="com.example.LbeforeAdvice"/> </property> </bean> <!-- 切面 --> <aop:config> <aop:aspect ref="pointcutAdvisor"> <aop:pointcut id="pointcut" expression="execution(* com.example.TargetObject.*(..))"/> <aop:before pointcut-ref="pointcut" method="before"/> </aop:aspect> </aop:config> </beans> ``` 其中,配置了一个目标对象 targetObject 和一个切入点通知器 pointcutAdvisor,使用正则表达式匹配目标对象的所有方法。在切面配置中,定义了一个切点 pointcut,匹配目标对象的所有方法。并将切点与前置通知 LbeforeAdvice 关联起来,在目标方法执行前执行 LbeforeAdvice 中的逻辑。 你可以根据自己的需要对配置文件进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值