Announcement Announcement Module
Collapse
No announcement yet.
Interceptors and bean names Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Interceptors and bean names

    Is it possible for MethodInterceptor (or similar) to have access to the Spring id/name of the bean it operates on? How would such configuration look like?

    thanks

  • #2
    This is normally not possible. The bean names/ids are only used by the spring container.

    The only approach I could think of is this:
    The proxied bean has to implement BeanNameAware so that it knows its name. Further it has to implement another interface that defines a getter for the bean name.
    A proxy can then check if the target bean implements that interface and can retrieve the bean name.

    If there are further proxies in-between things would not work out so fine. Anyway, I do not find that approach very nice.

    Regards,
    Andreas

    Comment


    • #3
      It's possible we will support this in 2.0 M3, to support a new bean() pointcut designator as part of the AspectJ Spring integration. I just committed an ExposeBeanNameAdvisor, which the autoproxying code may use in future. This is not certain, because there are some issues to resolve regarding eager pointcut evaluation, but it should certainly work in interceptors.

      Comment


      • #4
        Interceptors and bean names

        We had similar requirements as the OP.
        Is it possible for MethodInterceptor (or similar) to have access to the Spring id/name of the bean it operates on? How would such configuration look like?
        We see that ExposeBeanNameAdvisors is still in 3.x codebase and the javadoc mentions that the invocation needs to be exposed with ExposeInvocationInterceptor.

        Is ExposeBeanNameAdvisors still the appropriate approach for addressing such requirements? Is there a sample example or a testcase that would shed more light on exploring the use of the same?

        Is/are there alternate approach(es) for similar requirement(s)?

        Comment


        • #5
          How to use ExposeBeanNameAdvisors?

          This thread shows exactly what we need to do. We're using an interceptor to examine exceptions and take action when there's a "resource is down" exception with JDBC, JMS, etc.

          But we need to know the bean name to identify which resource it is.

          ExposeBeanNameAdvisors and ExposeInvocationInterceptor look pretty straightforward, but I'm not Spring AOP savvy enough to understand how to wire them in.

          Could someone chime in with some advice?

          Thanks

          Comment

          Working...
          X