0

I have a following hierarchical structure:

public class ItemImpl extends RepositoryBase<ItemImpl> { 
   @Inject
   ItemImpl( dependency ) { 
      super( dependency )
   }
}

public class RepositoryBase<T> extends Base<T> {
   public RepositoryBase( dependency ) { //Constructor without @Inject
      super( dependency )
   }

   @Intercept <--- Works
   public someMethod( ) {}
}

public class Base<T> {
   public Base( dependency ){ } //Constructor without @Inject

   @Intercept <--- Does not work ***
   public someMethod( ) {}
}

As you can see above, Interception does not work at the level 3 of the hierarchy. According to Guice's AOP limitation, instance have to be created using Guice and child ItemImpl has constructor with @Inject so I guessed parents of this child should work.

Why doesn't interception at level 3 work and why does the interception at level 2 work? Both of the parents does not have constructor with @Inject?

4

1 回答 1

0

Cglib 创建了一个动态子类,它覆盖了一个被拦截的方法,Guice 在这个被覆盖的方法中应用了它的魔力。这只能用于“顶级”方法,但不能用于“祖父”方法。因此,只有 in 中的方法RepositoryBase被拦截,而 in 中定义的方法对BaseGuice 隐藏。

请注意,在技术上可以创建调用祖父方法的字节码。然而,Cglib 不提供这样的功能。

于 2013-12-29T00:57:27.430 回答