-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AOP classes don't get the annotations of the superclass #201
Comments
From anthony.muller on May 30, 2008 02:41:16 package guice; import static com.google.inject.matcher.Matchers.annotatedWith; import java.lang.annotation.ElementType; import org.aopalliance.intercept.MethodInterceptor; import com.google.inject.AbstractModule; public class AnnotationTest { } void setBidule(String bidule); class TotoImpl implements Toto { private String bidule; public String getBidule() { static class MyInterceptor implements MethodInterceptor { public Object invoke(MethodInvocation mi) throws Throwable { } static class MyModule extends AbstractModule { public static void main(String[] args) throws Throwable { |
From limpbizkit on June 03, 2008 02:49:41 I'd like to know more -- is there a particular use case, tool or library that requires this? Summary: AOP classes don't get the annotations of the superclass |
From robbie.vanbrabant on June 03, 2008 10:13:19 As I noted on the mailing list, there's a workaround: You could use an Method setter = I'm also curious to see what the use case is though. |
From anthony.muller on June 03, 2008 12:26:08 My Use Case is quite simple, I add some annotations in my business classes like |
From limpbizkit on June 03, 2008 17:19:54 Chris - I'm totally ignorant of cglib's API, so I'll ask you. Would fixing this require a whole lot of code? Cc: chris.nokleberg |
From chris.nokleberg on June 03, 2008 17:49:45 It would require code to copy the annotations from the superclass to the subclass. It |
From limpbizkit on June 08, 2008 16:28:43 See also issue 101 . |
From botteaap on June 29, 2008 07:18:33 When integrating to existing frameworks annotation inheritence on the subclass is |
From gili.tzabari on November 24, 2008 08:19:07 FYI, Jersey has a new hook that allows me to pass it the unproxied class, it then |
From pavel.jbanov on November 24, 2008 09:28:00 In my particular use-case I had a problem with Struts2 |
From roger.gonzalez on September 16, 2009 18:31:19 I assume this issue also implies that parameter annotations are not copied to the proxy? I tried intercepting some service methods that use annotations to define parameter |
From joshgr on August 21, 2010 17:44:43 I've been very frustrated by this shortcoming myself: my team is using JPA/Hibernate with Guice. To facilitate a "rich domain model" (ie, domain-logic directly in our entity-classes), I'm using a Hibernate Interceptor to augment Hibernate's Entity-instantiation, and constructing the entity instances with a Guice Injector. This enables Guice AOP and injection in our Entity instances: we can annotate model-methods with This works beautifully, EXCEPT that the standard JPA method annotations for lifecycle-event observers ( I'm currently building a workaround involving a class-level EntityListener that will look up-the-tree to find and invoke persistence-event annotations, but this is very cumbersome and, more importantly, doesn't feel like it should be my concern: Guice is constructing my objects and providing "magic" AOP, but the abstraction is leaking here. If it's too expensive to perform method-annotation-preservation by default, it seems appropriate that the framework should at least support it upon request, as a binding configuration..? Annotation-based tools and functionality continue to become more pervasive; I anticipate the impact of this subtle failure may become more common and expensive for guice-enhanced developers. Plz fix. |
From cgruber@google.com on July 16, 2012 11:13:27 (No comment was entered for this change.) Status: Acknowledged |
From leitao.otavio on February 16, 2014 09:50:33 I'm facing the very same problem joshgr described and it's really frustrating. I just add a method annotation and Guice stops "coping" some (others) annotations to the proxy object. Please, fix it! |
Yeah I'm also a little shocked that this has gone on for 6 years now... I'm trying to add AOP to intercept the methods in a Dropwizard service and this totally kills that idea. |
I think I've fixed this issue by writing a custom method matcher - please see https://codingcraftsman.wordpress.com/2018/11/11/google-guice-aop-with-interface-annotations/ and feedback if it's a solution for you. |
Building on @ashleyfrieze's solution, here's a bit of code that looks for the "real" method. Fortunately in our code we were able to substitute the proxied method for the real method in the specific scenario where this was failing for us:
|
From anthony.muller on May 30, 2008 05:41:03
@
ME :I'm quite suprised... I annoted a method
@
MyAnnotation, in order tointercept calls of this method. My problem is when I instanciate an object
which has a such annotation using guice. when i search the annoted method
through reflection, and i call isAnnotationPresent(MyAnnotation.class),
this method returns false!
@
jesse@
swank.ca: Under the hood, Guice creates a subclass of TotoImplin order to perform method interception.
For the most part, this is completely transparent to
the developer, but there's a few consequences. getClass()
doesn't return TotoImpl.class. This constraints how your
equals() method must be implemented.
I also expect Serializable won't interoperate with
method interception.
The workaround in this case is to use TotoImpl.class
rather than toto.getClass() to introspect on your
type.
Original issue: http://code.google.com/p/google-guice/issues/detail?id=201
The text was updated successfully, but these errors were encountered: