Are you really using Guice to inject instances of Company into your 
classes? Guice will only intercept methods on objects that it instantiates 
itself (see https://github.com/google/guice/wiki/AOP#limitations) If you 
want broader use of AOP, you'll have to use another tool, such as AspectJ.
Oh, and I see your foo method is 'static', that's not going to work either, 
as it cannot be overridden.

On Monday, May 15, 2017 at 1:30:07 PM UTC+2, shishir gowda wrote:
>
> I have ebean entity:
>
>     
>     @Entity
>     public class Company extends Model {
>     @Id
>          public Long id;
>          static void foo {
>                Logger.info("in company");
>          }
>     ...
>     }
>
> A guice Module defining the interceptor:
>
>     
>     public class Module extends AbstractModule {
>         protected void configure() {
>
>             CacheImpl cache = new CacheImpl();
>             requestInjection(cache);
>             bindInterceptor(subclassesOf(Company.class), any(), cache);
>
>         }
>     }
>
> This does not intercept any calls made to Company (foo(), save(),get(), 
> find()..)
>
> When I change bindInterceptor to a class extending Play Controller, it 
> works by intercepting the calls.
>
> Can some one tell me if I am missing anything?
>
> my methodInterceptor:
>
>     @Component
>     public class CacheImpl implements MethodInterceptor {
>
>         public Object invoke(MethodInvocation method) throws Throwable{
>             Logger.info("class {}",method.getClass().getName());
>             if (method.getMethod().getName() == "list") {
>                 Logger.info("interceptor in list");
>             } else {
>                 Logger.info("in interceptor for  {}", 
> method.getMethod().getName());
>
>             }
>             return method.proceed();
>
>         }
>     }
>
>    
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/7bba8281-2148-4ec2-9e48-a506c1464864%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to