Announcement Announcement Module
Collapse
No announcement yet.
Mistake of "Type mismatch" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mistake of "Type mismatch"

    I want to exercise AOP,so I use follwing example code:

    Code:
    package com.apress.prospring3.ch6.staticpc;
    import java.lang.reflect.Method;
    import net.sf.cglib.proxy.MethodInterceptor;
    import net.sf.cglib.proxy.MethodProxy;
    import org.aopalliance.intercept.MethodInvocation;
    public class SimpleAdvice implements MethodInterceptor {
    	@Override
    	public Object intercept(Object arg0, Method arg1, Object[] arg2,
    			MethodProxy arg3) throws Throwable {
    		// TODO Auto-generated method stub
    		return null;
    	}
    	public Object invoke(MethodInvocation invocation) throws Throwable{
    		System.out.println(">> Invoking "+invocation.getMethod().getName());
    		Object retVal=invocation.proceed();
    		System.out.println(">> Done");
    		return retVal;
    	}
    }
    Code:
    package com.apress.prospring3.ch6.staticpc;
    import org.aopalliance.aop.Advice;
    import org.springframework.aop.Advisor;
    import org.springframework.aop.Pointcut;
    import org.springframework.aop.support.DefaultPointcutAdvisor;
    public class StaticPointcutExample {
    	public static void main(String[] args){
    		BeanOne one=new BeanOne();
    		BeanTwo two=new BeanTwo();
    		BeanOne proxyOne;
    		BeanTwo proxyTwo;
    		Pointcut pc=new SimpleStaticPointcut();
    		Advice advice=new SimpleAdvice();  //compile error here
    	}
    }
    When I run StaticPointcutExample ,it raise following error:
    Code:
    Type mismatch: cannot convert from SimpleAdvice to Advice
    Where is wrong? How to correct it?
    Thanks

  • #2
    For starters your advice implements the wrong interface... You should imlpement the one from the org.aopalliance package not the one from cglib (this should also be apparent from your compilation exception).

    Comment

    Working...
    X