cargoj 2012-08-22 14:36 采纳率: 100%
浏览 278
已采纳

通过CGLIB实现AOP动态切换数据源,代理失败

[code="java"]
public class DatasourceBeforeAdvice implements MethodBeforeAdvice{

@Override
public void before(Method method, Object[] args, Object target)
        throws Throwable {
    // TODO Auto-generated method stub
    String serverCode = (String)args[0];
    for(CustomerType ct : CustomerType.values()){
        if(ct.toString().equals(serverCode)){
            CustomerContextHolder.setCustomerType(ct);
            break;
        }
    }
}

}
[/code]
[code="java"]






dsBeforeAdvice



[/code]
结果没有进入advice,代理失败,请教一下原因。

  • 写回答

1条回答 默认 最新

  • jinnianshilongnian 2012-08-22 14:48
    关注

    没有指定target
    void setTarget(Object target)
    Set the given object as target.

    1、targetClass:Set a target class to be proxied, indicating that the proxy should be castable to the given class. (指定代理的类的类型 会把目标对象转成该类型进行代理)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?