All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.m1c.frame.component.DataSourceAspect Maven / Gradle / Ivy

package cn.m1c.frame.component;

import java.lang.reflect.Method;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
/**
 * 2016年11月19日  使用aop动态改变数据源
 * @author  phil([email protected],m1c softCo.,ltd)
 * @version lannie
 */
public class DataSourceAspect {

    public void before(JoinPoint point)
    {
        Object target = point.getTarget();
        String method = point.getSignature().getName();

        Class[] classz = target.getClass().getInterfaces();

        Class[] parameterTypes = ((MethodSignature) point.getSignature())
                .getMethod().getParameterTypes();
        try {
            Method m = classz[0].getMethod(method, parameterTypes);
            if (m != null && m.isAnnotationPresent(DataSource.class)) {
                DataSource data = m
                        .getAnnotation(DataSource.class);
                DynamicDataSourceHolder.putDataSource(data.value());
                System.out.println(data.value());
            }
            
        } catch (Exception e) {
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy