Results 1 to 8 of 8

Thread: Advising components not managed by spring

Hybrid View

  1. #1

    Default Advising components not managed by spring

    I have component which is not managed by Spring Container. It is created using new from third party library. I want intercept some of these component methods. I have read the documentation for LTW and it says to annotate the component with @Configurable and then this will eligible for Spring driven configuration . But I have no control over this component to annotate it.
    How can I intercept such component methods?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Use loadtimeweaving @Configurable isn't needed for using loadtimeweaving.

    I advice you to read about the different weaving options (runtime, loadtime, compile) then you notice you don't need @Configurable.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    Marten,
    Thx for the response. I was going thru the document, but not successful in finding what I need. Can you point me the link?

    For instance, let's say I'm using a third party library and one of their classes uses javax.jms.TopicSession. Now I want to intercept these session methods and my provide my own behavior in my interceptor class (SessionAOPInterceptor).

    This is my sample config file.

    Code:
    <aop:config>
    	<aop:aspect id="myAspect" ref="SessionInterceptordvice">
    	<aop:pointcut id="myPointCut" expression="execution(* javax.jms.Session.*(..))"/>
    	<aop:around pointcut-ref="myPointCut" method="createCustomTopic"/>
    	</aop:aspect>
    </aop:config>
    
    <bean name="SessionInterceptordvice" class="com.gtech.aop.SessionAOPInterceptor"> </bean>

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    As stated before use 'loadtimeweaving' chapter 6 of the reference guide explains quite clearly on how to set it up.

    You are currently not using loadtimeweaving but a proxy based approach.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5

    Default

    Thx for pointing me to the correct location in spring ref document. It works now with loadtimeweaving.

    Is there a way where I can set some custom properties in the aspect class when using LTW?

    For instance, using proxy approach I was setting some of the required properties on the Aspect as below

    Code:
    <bean name="SessionInterceptordvice" class="com.gtech.aop.SessionAOPInterceptor"> 
      <property name="requiredProperty" value="testValue"/>
    </bean>
    Now my aspect looks like below when using LTW. How can I invoke setRequiredProperty() method? I need this property to be set before customeCreateDestination() is invoked? Any ideas?

    Code:
    @Aspect
    public class SessionAOPIntercepto {
    
    	private String requiredProperty;
    	
    	@Around("methodsToBeProfiled()")
    	public Object customCreateDestination(ProceedingJoinPoint call) throws Throwable { 
             //method implementation here
            }
    
            public void setRequiredProperty(String requiredProperty) {
    		this.requiredProperty = requiredProperty;
    	}
    
           @Pointcut("execution(public * javax.jms.Session.create*(..))")
    	public void methodsToBeProfiled(){}
    }

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Like anyother spring bean.... Simply configure it.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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