Announcement Announcement Module
Collapse
No announcement yet.
Advising non-spring created objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Advising non-spring created objects

    Hi All,

    All of the examples I have seen online show Spring advising objects which have been created through the Spring XML. Example:

    Code:
    <bean id="personTarget" class="com.mycompany.PersonImpl">
        <property name="name"><value>Tony</value></property>
        <property name="age"><value>51</value></property>
    </bean>
    
    <bean id="person" 
        class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="proxyInterfaces"><value>com.mycompany.Person</value></property>
    
        <property name="target"><ref local="personTarget"/></property>
        <property name="interceptorNames">
            <list>
                <value>myAdvisor</value>
                <value>debugInterceptor</value>
            </list>
        </property>
    </bean>
    Here we are advising specifically the "personTarget" class only.

    My question - can you easily advise objects which have been instantiated through Java, not Spring. Eg:

    Code:
    public class PersonTarget {
        public void someMethod(){...}
    }
    
    ...
    
    PersonTarget person = new PersonTarget();
    person.someMethod();
    ... and then a Spring definition which advises this code? I may not be making myself clear, but we have a large codebase and only a tiny fraction uses Spring IoC, but we want to advise on all of it.

    Thanks

  • #2
    You can do that via AspectJ Spring integration. Check corresponding reference documentation about that - 6.8. Using AspectJ with Spring applications. This forum contains examples of load-time weaving and references to the aspectj documentation.

    Comment

    Working...
    X