org.springframework.aop.framework.ProxyProcessorSupport Java Examples

The following examples show how to use org.springframework.aop.framework.ProxyProcessorSupport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AopUtils.java    From springboot-plugin-framework-parent with Apache License 2.0 6 votes vote down vote up
/**
 * 解决AOP无法代理到插件类的问题
 * @param applicationContext 插件包装类
 */
public static synchronized void registered(ApplicationContext applicationContext) {
    Map<String, ProxyProcessorSupport> beansOfType = applicationContext
            .getBeansOfType(ProxyProcessorSupport.class);
    if(beansOfType.isEmpty()){
        LOG.warn("Not found ProxyProcessorSupports, And Plugin AOP can't used");
        return;
    }
    for (ProxyProcessorSupport support : beansOfType.values()) {
        if(support == null){
            continue;
        }
        ProxyWrapper proxyWrapper = new ProxyWrapper();
        proxyWrapper.setProxyProcessorSupport(support);
        PROXY_WRAPPERS.add(proxyWrapper);
    }
}
 
Example #2
Source File: AopUtils.java    From springboot-plugin-framework-parent with Apache License 2.0 6 votes vote down vote up
/**
 * 解决AOP无法代理到插件类的问题
 * @param pluginWrapper 插件包装类
 */
public static synchronized void resolveAop(PluginWrapper pluginWrapper){
    if(PROXY_WRAPPERS.isEmpty()){
        LOG.warn("ProxyProcessorSupports is empty, And Plugin AOP can't used");
        return;
    }
    if(!isRecover.get()){
        throw new RuntimeException("Not invoking resolveAop(). And can not AopUtils.resolveAop");
    }
    isRecover.set(false);
    ClassLoader pluginClassLoader = pluginWrapper.getPluginClassLoader();
    for (ProxyWrapper proxyWrapper : PROXY_WRAPPERS) {
        ProxyProcessorSupport proxyProcessorSupport = proxyWrapper.getProxyProcessorSupport();
        ClassLoader classLoader = getClassLoader(proxyProcessorSupport);
        proxyWrapper.setOriginalClassLoader(classLoader);
        proxyProcessorSupport.setProxyClassLoader(pluginClassLoader);
    }
}
 
Example #3
Source File: AopUtils.java    From springboot-plugin-framework-parent with Apache License 2.0 5 votes vote down vote up
/**
 * 恢复AOP 的 BeanClassLoader
 */
public static synchronized void recoverAop(){
    if(PROXY_WRAPPERS.isEmpty()){
        return;
    }
    for (ProxyWrapper proxyWrapper : PROXY_WRAPPERS) {
        ProxyProcessorSupport proxyProcessorSupport = proxyWrapper.getProxyProcessorSupport();
        proxyProcessorSupport.setProxyClassLoader(proxyWrapper.getOriginalClassLoader());
    }
    isRecover.set(true);
}
 
Example #4
Source File: AopUtils.java    From springboot-plugin-framework-parent with Apache License 2.0 5 votes vote down vote up
/**
 * 反射获取代理支持处理者的ClassLoader属性值
 * @param proxyProcessorSupport proxyProcessorSupport
 * @return ClassLoader
 */
private static ClassLoader getClassLoader(ProxyProcessorSupport proxyProcessorSupport){
    Class aClass = proxyProcessorSupport.getClass();
    while (aClass != null){
        if(aClass != ProxyProcessorSupport.class){
            aClass = aClass.getSuperclass();
            continue;
        }
        Field[] declaredFields = aClass.getDeclaredFields();
        if(declaredFields == null || declaredFields.length == 0){
            break;
        }
        for (Field field : declaredFields) {
            if(Objects.equals("proxyClassLoader", field.getName()) || field.getType() == ClassLoader.class){
                field.setAccessible(true);
                try {
                    Object o = field.get(proxyProcessorSupport);
                    if(o instanceof ClassLoader){
                        return (ClassLoader) o;
                    } else {
                        LOG.warn("Get {} classLoader type not is ClassLoader type,  And Return DefaultClassLoader",
                                aClass.getName());
                        return ClassUtils.getDefaultClassLoader();
                    }
                } catch (IllegalAccessException e) {
                    LOG.error("Get {} classLoader failure {}, And Return DefaultClassLoader",
                            aClass.getName(),
                            e.getMessage());
                    return ClassUtils.getDefaultClassLoader();
                }
            }
        }

    }
    LOG.warn("Not found classLoader field, And Return DefaultClassLoader",
            aClass.getName());
    return ClassUtils.getDefaultClassLoader();
}
 
Example #5
Source File: AopUtils.java    From springboot-plugin-framework-parent with Apache License 2.0 4 votes vote down vote up
ProxyProcessorSupport getProxyProcessorSupport() {
    return proxyProcessorSupport;
}
 
Example #6
Source File: AopUtils.java    From springboot-plugin-framework-parent with Apache License 2.0 4 votes vote down vote up
void setProxyProcessorSupport(ProxyProcessorSupport proxyProcessorSupport) {
    this.proxyProcessorSupport = proxyProcessorSupport;
}