Announcement Announcement Module
Collapse
No announcement yet.
Detecting Proxies and using Bean Introspection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Detecting Proxies and using Bean Introspection

    I need to create a prototype bean and then iterate over it's properties. I've been doing this with java.beans.Introspector and that works fine.

    However, when the prototype bean has a method that is annotated with for example @Transactional, the instance that I get back from the BeanFactory is a proxy. A JdkDynamicAopProxy to be precise.

    This is expected of course, but now the bean introspection does not work anymore. The Introspector gives back the properties of the proxy and not of the proxied object.

    What is a good way to deal with this? Does Spring contain a proxy-aware Introspector alternative or should specifically check in my code if the bean has been proxied?

    S.

  • #2
    You have two options depending on what you want to do:

    1. for reflection you can use AopUtils.getTargetClass(Object)
    2. if you need access to the actual target object you can use Object AopContext.currentProxy()

    Hope this helps.

    Comment


    • #3
      Originally posted by Stefan Schmidt View Post
      You have two options depending on what you want to do:

      1. for reflection you can use AopUtils.getTargetClass(Object)
      2. if you need access to the actual target object you can use Object AopContext.currentProxy()

      Hope this helps.
      Thanks Stefan, the AopUtils.getTargetClass was exactly what I needed!

      S.

      Comment

      Working...
      X