Announcement Announcement Module
No announcement yet.
Proxy for 3rd party interface Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Proxy for 3rd party interface

    what i want to do: declare "before" advices for the nullSafeSet methods of the org.hibernate.type.Type interface (from the hibernate3 library)

    what I have found in the docs (
    "Spring AOP only supports method execution join points for Spring beans, so you can think of a pointcut as matching the execution of methods on Spring beans"

    As I do not have a bean declaration for the Type interface, does this mean it's impossible to do it in Spring?

  • #2
    It depends...

    By default Spring AOP works via a proxy based mechanism and with that it is impossible to declare a before advice on non spring managed beans. For that to work you would have to use loadtime weaving to enhance those classes.


    • #3
      You could also use the AspectJ language to specify a pointcut on the call to that 3rd party class.


      • #4
        in the docs, Spring LTW is explained on Java 5. I'm in a 1.4 environment.

        what I did (applicationContext.xml):
        	<bean id="hibernateQueryAdvisor" class="">
        		<aop:aspect ref="hibernateQueryAdvisor">
        			<aop:before method="exposeQueryParameters" pointcut="execution(* org.hibernate.type.Type.nullSafeSet(..))"/>
        the advisor:
        import org.apache.commons.logging.Log;
        import org.apache.commons.logging.LogFactory;
        import org.aspectj.lang.ProceedingJoinPoint;
        import org.hibernate.type.Type;
        public class HibernateQueryAdvisor {
        	private static Log logger = LogFactory.getLog(HibernateQueryAdvisor.class);
        	//cache this, because it was a significant performance cost;
        	private static final boolean IS_TRACE_ENABLED = logger.isTraceEnabled();
        	public Object exposeQueryParameters(ProceedingJoinPoint call) throws Throwable {
        		try {
        			if ( IS_TRACE_ENABLED ) {
        				if (call.getTarget() instanceof Type) {
        					final Object[] args = call.getArgs();
        					Object value = args[1];
        					Object index = args[2];
        					logger.trace( "binding '" + value + "' to parameter: " + index );
        			return call.proceed();
        		} finally {
        			// do nothing
        however, this "breaks" the initialisation of at least one unrelated Spring bean and my context no longer loads.

        can this really be done in Spring 2.0.3, using only <aop:xxx> tags, in a 1.4 environement?


        • #5
          No... Spring AOP works proxy based and proxies are only generated for beans defined in the Spring context. LTW is also only available from JDK 1.5+.

          Originally posted by -FoX-
          You could also use the AspectJ language to specify a pointcut on the call to that 3rd party class.
          call isn't supported for AspectJ i.c.m. with Spring AOP, for that to work you would need LTW or CTW.