V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
palmers
V2EX  ›  程序员

请教大家: 我在使用 spring aop aspect 穿件一个切面的时候, Pointcut 表达式一直不能匹配,但是我找不到表达式错误的地方,麻烦大家帮我看看, 谢谢大家!!!

  •  
  •   palmers · 2017-03-01 11:40:50 +08:00 · 3636 次点击
    这是一个创建于 2606 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我需要匹配 abc.cde.A.fun(cv.bc.F f,Map<String,String> map)方法,然后切面类中内容如下:

    @Aspect
    @Component
    public class Inte {
    
    
        @Pointcut("execution(* abc.cde.A.fun(..))")
        public void pointcut() {
            //
        }
    
    
    
        @Before("pointcut()")
        public void bef() {
            System.out.println("before ---------called.......");
        }
    }
    

    以上, 当A#fun方法被调用的时候并没有进入bef方法, 然后我修改了上面Pointcut表达式为: execution(* *.*(..)) 则所有方法调用都会触发bef切面方法, 所以我spring配置应该是没有问题的.

    第一次使用, 麻烦大家帮我看看 谢谢!!!

    第 1 条附言  ·  2017-03-01 17:25:12 +08:00

    该问题更换方式后已解决, 采用xml方法配置aspect 已经可以正常使用! annotation方式一直不能生效, 等工作完成后, 我会继续研究是否因为缺包原因导致, 如果有进展,我会附加问题原因. 谢谢大家!

        <bean id="inte" class="abc.aspect.MyAspect"/>
    
        <aop:config>
            <aop:aspect id="aspect" ref="inte">
                <aop:pointcut id="point" expression="execution(* abc.cde.A.fun(..))" />
                <!--<aop:before method="defore" pointcut-ref="point"/>-->
                <!--<aop:around method="around" pointcut-ref="point"/>-->
                <aop:after-returning method="aftert" pointcut-ref="point" returning="retVal"/>
            </aop:aspect>
        </aop:config>
    

    参考链接: https://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html

    3 条回复    2017-03-02 21:14:02 +08:00
    wc951
        1
    wc951  
       2017-03-02 20:52:13 +08:00
    官方参考文档里切点使用的 private 修饰符,不知道和这个有没有关系
    palmers
        2
    palmers  
    OP
       2017-03-02 21:03:26 +08:00
    @wc951 不是的 大概是 idea 的问题, 在 eclipse 环境下是可以正常执行
    wc951
        3
    wc951  
       2017-03-02 21:14:02 +08:00
    但我感觉官方文档里说的公用切入点是要写全路径的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2598 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 01:39 · PVG 09:39 · LAX 18:39 · JFK 21:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.