I have a base class with several derived classes that extend it.
I want to restrict my Spring AOP Aspect to the superclass only, so that the AOP Proxy would be created for it only and not for the derived classes.
I tried to define the pointcut as follows:
@Pointcut("execution(* com.blah.platform.persistence.generic.GenericDaoImpl.*(..))")
public void withinGenericDao() {}
where GenericDaoImpl is the superclass.
I still can see that proxies are generated for the derived classes as well:
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]
I would think that this should only happen when the pointcut is defined as follows:
execution(public * com.mycompany.myservice.MyService+.*(..))
Any ideas?
Can you change your
PointCutdefinition fromexecutiontowithin? I have had success with that in the past. (Note that the syntax is a little different. See the Spring AOP reference documentation for details.)e.g.
@PointCut("within(com.blah.platform.persistence.generic.GenericDaoImpl)")