V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
palmers
V2EX  ›  程序员

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

  •  
  •   palmers · Mar 1, 2017 · 4218 views
    This topic created in 3347 days ago, the information mentioned may be changed or developed.

    我需要匹配 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配置应该是没有问题的.

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

    Supplement 1  ·  Mar 1, 2017

    该问题更换方式后已解决, 采用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 replies    2017-03-02 21:14:02 +08:00
    wc951
        1
    wc951  
       Mar 2, 2017
    官方参考文档里切点使用的 private 修饰符,不知道和这个有没有关系
    palmers
        2
    palmers  
    OP
       Mar 2, 2017
    @wc951 不是的 大概是 idea 的问题, 在 eclipse 环境下是可以正常执行
    wc951
        3
    wc951  
       Mar 2, 2017
    但我感觉官方文档里说的公用切入点是要写全路径的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   941 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 19:00 · PVG 03:00 · LAX 12:00 · JFK 15:00
    ♥ Do have faith in what you're doing.