Affects: \ 5.2.15


this method: org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#createProxy

471 line: why use return proxyFactory.getProxy(getProxyClassLoader());

i think can use return proxyFactory.getProxy(beanClass.getClassLoader());

When I use a plugin, I need to perform class isolation, and the bean will have a class isolation scenario. When I register the bean in the plugin to spring cotext, and then aop acts on the bean in the plugin, there will be a class not found error

Comment From: bclozel

The behavior you're asking for should be the default one. From the getProxyClassLoader Javadoc

Default is the bean ClassLoader, i.e. the ClassLoader used by the containing org.springframework.beans.factory.BeanFactory for loading all bean classes. This can be overridden here for specific proxies.

Please provide a sample application that demonstrates the problematic behavior and explain what you were expecting instead.

Comment From: stateIs0

@bclozel I may not express well, what I want to express is that all beans in spring, each bean has a different classloader, and aop has only one classloader.

I have a directory with multiple jar packages, each jar package has a classloader, and the classes in the package will be registered to the spring container. If spring aop has only one classloader, it cannot handle this situation. The code example is more complicated and not easy to post

Comment From: stateIs0

@Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
        if (started) {
            return;
        }
        try {
            synchronized (BeanDefinitionRegistryPostProcessorEEP.class) {
                if (started) {
                    return;
                }

                map = new EEPBootstrap().start();
                for (IPluginBeanRegister value : map.values()) {
                    value.postProcessBeanDefinitionRegistry((aClass, pluginClassLoader) -> {
                        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(aClass);
                        BeanDefinition beanDefinition = builder.getBeanDefinition();
                        beanDefinitionRegistry.registerBeanDefinition(aClass.getName(), beanDefinition);
                        log.info("------->>>> 插件 register beanName:{}", aClass.getName());
                    });
                }

                started = true;
            }

        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

Comment From: stateIs0

The beans in the map are all class-isolated

Comment From: bclozel

that all beans in spring, each bean has a different classloader, and aop has only one classloader.

I don't think this use case is valid for a Spring application context. I think separate application contexts are needed for isolation if different classloaders are expected: within an application context, all beans are supposed to be candidates for injection. I'm closing this issue as a result.