2009/11/10 Nirav Shah <[email protected]>

>
> Hello !
>
> I created an object instance of a Class with custom annotations using
> Guice.
> But the created instance did not retain any of the annotations on my
> class.
>
> I have copied the example am trying to run at the end of this message.
> Any idea what's happening here?
>

probably the AOP proxies - a lot of proxy frameworks (like CGLIB)
don't support creation of classes with annotations at the moment,
which is why your proxy class is missing its method annotations

try accessing the proxy superclass and you should see them

see also:
http://sourceforge.net/tracker/?func=detail&aid=2255414&group_id=56933&atid=482371

Cheers!
> Nirav
>
> /**************** CODE START ******************/
>
> import java.lang.annotation.Annotation;
> import java.lang.annotation.ElementType;
> import java.lang.annotation.Retention;
> import java.lang.annotation.RetentionPolicy;
> import java.lang.annotation.Target;
> import java.lang.reflect.Method;
>
> import org.aopalliance.intercept.MethodInterceptor;
> import org.aopalliance.intercept.MethodInvocation;
>
> import uk.co.netdev.cie2.rest.gui.GuiBT;
> import uk.co.netdev.cie2.util.CieSecurity;
>
> import com.google.inject.Guice;
> import com.google.inject.Injector;
> import com.google.inject.matcher.Matchers;
>
> public class GuiceAOP {
>
>        @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD)
>        public @interface CheckCiePermissions {}
>
>        public class CieSecurityModule extends CieSecurity{
>                @Override
>                protected void configure() {
>                        bindInterceptor(Matchers.any(),
> Matchers.annotatedWith
> (CheckCiePermissions.class), new SecurityInterceptor());
>                }
>        }
>
>        public static class SecurityInterceptor implements MethodInterceptor
> {
>                  public Object invoke(MethodInvocation invocation) throws
> Throwable
> {
>                          System.out.println("Security Interceptor
> Invoked");
>                          return invocation.proceed();
>                  }}
>
>
>        public static class TestGuice{
>                @CheckCiePermissions
>                @GuiBT
>                public String sayHello(){
>                        return "Hello";
>                }
>        }
>
>        public static void main(String[] args) {
>                GuiceAOP guiceTest = new GuiceAOP();
>                Injector injector = Guice.createInjector(guiceTest.new
> CieSecurityModule());
>
>                TestGuice test = injector.getInstance(TestGuice.class);
>                for(Method method : test.getClass().getMethods()){
>                        for(Annotation annot : method.getAnnotations()){
>                                System.out.println("Object created using
> Guice: " +
> annot.annotationType().getName());
>                        }
>                }
>
>                TestGuice test2 = new TestGuice();
>                for(Method method : test2.getClass().getMethods()){
>                        for(Annotation annot : method.getAnnotations()){
>                                System.out.println("Object created using
> new(): " +
> annot.annotationType().getName());
>                        }
>                }
>
>        }
>
> }
>
>
> /**************** CODE END ******************/
> >

-- 
Cheers, Stuart

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to