【问题标题】:Spring AOP - How to prevent derived classes from being targetedSpring AOP - 如何防止派生类成为目标
【发布时间】:2011-11-24 16:13:51
【问题描述】:

我有一个基类,其中有几个扩展它的派生类。 我只想将我的 Spring AOP Aspect 限制为超类,以便仅为它创建 AOP 代理,而不是为派生类创建。

我尝试将切入点定义如下:

@Pointcut("execution(* com.blah.platform.persistence.generic.GenericDaoImpl.*(..))")
public void withinGenericDao() {}

其中 GenericDaoImpl 是超类。

我仍然可以看到为派生类生成了代理:

2011-11-24 18:00:28,616 ContainerBackgroundProcessor[StandardEngine[Catalina]] DEBUG [JdkDynamicAopProxy] Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [com.blah.admin.persistence.impl.CircuitDAOImpl@5c81cf46]
2011-11-24 18:00:28,638 ContainerBackgroundProcessor[StandardEngine[Catalina]] DEBUG [JdkDynamicAopProxy] Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [com.blah.admin.persistence.impl.CategoryDAOImpl@55eef3c1]
2011-11-24 18:00:28,645 ContainerBackgroundProcessor[StandardEngine[Catalina]] DEBUG [JdkDynamicAopProxy] Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [com.blah.admin.services.circuit.impl.CircuitsServiceImpl@d50112d]
2011-11-24 18:00:28,953 ContainerBackgroundProcessor[StandardEngine[Catalina]] DEBUG [JdkDynamicAopProxy] Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [com.blah.events.persistence.impl.EventsDAOImpl@4222023a]
2011-11-24 18:00:29,030 ContainerBackgroundProcessor[StandardEngine[Catalina]] DEBUG [JdkDynamicAopProxy] Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [com.blah.events.persistence.impl.PrototypesDAOImpl@d3bef50]

我认为只有在切入点定义如下时才会发生这种情况:

execution(public * com.mycompany.myservice.MyService+.*(..))

有什么想法吗?

【问题讨论】:

    标签: java spring spring-aop


    【解决方案1】:

    您能否将您的PointCut 定义从execution 更改为within?我过去在这方面取得了成功。 (注意语法有点不同,详见 Spring AOP 参考文档。)

    例如@PointCut("within(com.blah.platform.persistence.generic.GenericDaoImpl)")

    【讨论】:

      【解决方案2】:

      子类继承父类的公共方法和属性,包括您的注释。

      【讨论】:

        猜你喜欢
        • 2020-03-13
        • 1970-01-01
        • 1970-01-01
        • 2015-11-04
        • 2014-01-09
        • 2017-05-29
        • 2020-04-07
        • 2016-10-14
        • 1970-01-01
        相关资源
        最近更新 更多