net.eudu.db.proxy.MyAutoProxy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of db Show documentation
Show all versions of db Show documentation
simplify database access
The newest version!
package net.eudu.db.proxy;
import net.eudu.db.annotation.MyDBInterceptor;
import net.eudu.db.annotation.MyDb;
import net.eudu.db.interceptlogic.NamedMyInterceptor;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import org.springframework.beans.BeansException;
import org.springframework.stereotype.Component;
import java.lang.annotation.Annotation;
//@Component
public class MyAutoProxy extends AbstractAutoProxyCreator {
NamedMyInterceptor namedMyInterceptor;
public MyAutoProxy(NamedMyInterceptor namedMyInterceptor) {
Annotation annotation = namedMyInterceptor.getClass().getDeclaredAnnotation(MyDBInterceptor.class);
if (annotation == null) {
throw new RuntimeException("未找到 @MyDBInterceptor注解的实例");
}
this.namedMyInterceptor = namedMyInterceptor;
}
@Override
protected boolean shouldSkip(Class> beanClass, String beanName) {
if (super.shouldSkip(beanClass, beanName)) {
return true;
}
Annotation mydb = beanClass.getDeclaredAnnotation(MyDb.class);
if (mydb == null) {
return true;
}
return false;
}
@Override
protected Object[] getAdvicesAndAdvisorsForBean(Class> beanClass, String beanName, TargetSource customTargetSource) throws BeansException {
return new Object[]{
// new MethodBeforeAdvice() {
// @Override
// public void before(Method method, Object[] args, Object target) throws Throwable {
// System.out.println("wocao l ");
// }
// },
this.namedMyInterceptor};
// return null;
}
}