Announcement Announcement Module
Collapse
No announcement yet.
@Configurable and <replaced-method/> Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Configurable and <replaced-method/>

    I have successfully been able to get @Configurable working for properties, however <replaced-method/> doesnt have any affect at all on the bean.

    Am I missing something or is this simply a bug? I am using the latest snapshot (spring-framework-2.0-rc4-build.120-20060822.zip)

    Thanks for any help!

  • #2
    Can you show code snippet of what you are trying to do?

    -Ramnivas

    Comment


    • #3
      Thanks for the reply....

      its pretty simple, I have class which implements the org.springframework.beans.factory.support.MethodRe placer interface, and I have a domain object with the @Configurable notation.

      and then in the config:

      <!-- ========================== METHODREPLACERS================= -->
      <bean name="methodReplacer" scope="prototype" class="com.test.MyMethodReplacer" />

      <!-- ============ SPRING-MANAGED DOMAIN OBJECTS ================ -->
      <bean id="domainObject" scope="prototype" class="com.test.DomainObject">
      <replaced-method name="getProperty" replacer="methodReplacer" />
      <property name="property2" value="testValue" />
      </bean>

      This above example works fine if I get a handle to the domain object via the application context, however if I just create a new one, the "getProperty" method is not replaced -- I am sure the aspectj compilation is working however because the property I set in this config (property2) is set as expected.

      Thank you for any assistance

      Comment


      • #4
        Ok...

        The current support for @Configurable is designed to work only for properties. However, since you are already using AspectJ, you can quite easily implement the replaced-method functionality yourself:

        Code:
        public aspect DomainObjectMethodReplacer {
            Object around(DomainObject do) : execution(* DomainObject.getProperty()) && this(do) {
                // This could be really anything really, specifically
                // doesn't have to be a method on DomainObject or 
                // even a method call (could return a constant or a field for that matter)
                return do.replacedGetProperty();
            }
        }
        -Ramnivas

        Comment


        • #5
          Thanks for the help.

          Is this a feature on the roadmap, or is @Configurable always going to be a property-only annotation?

          Comment


          • #6
            Will remain property-only

            It looks like @Configurable will always be property-only, since implementing the replaced-method feature will be quite difficult, if not impossible, in general case. With application context usage, a CGLIB-enabled subclass of the specified class is used to instantiate the bean. The subclass contains the bytecode needed for method replacement. With @Configurable usage, the object is already created (by an ORM framework, for example). This is too late for subclassing. Further, since you want only that bean to have the method replaced, it is incorrect to modify bytecode for the class (even if you could somehow modify bytecode for already loaded object).

            -Ramnivas

            Comment

            Working...
            X