Results 1 to 2 of 2

Thread: Advising non-spring created objects

  1. #1
    Join Date
    Oct 2008
    Posts
    2

    Default 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. #2
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •