Announcement Announcement Module
No announcement yet.
@Configurable and <replaced-method/> Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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 (

    Thanks for any help!

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



    • #3
      Thanks for the reply....

      its pretty simple, I have class which implements the 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" />

      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


      • #4

        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:

        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();


        • #5
          Thanks for the help.

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


          • #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).