I am using the ServiceLoaderFactoryBean class in spring-bean 3.0.5.RELEASE with a MyCustomClassLoader as value of ServiceLoaderFactoryBean.beanClassLoader.
I am finding that the org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory is behaving unexpectedly and initially setting the property to MyCustomClassLoader as expected but then changing it to the default ClassLoader Launcher$AppClassLoader.
Am I doing something wrong or is there a bug at play.
Here is my spring configuration:
I notice in the debugger that there a ServiceLoaderFactoryBean inheritance hierarchy where the beanClassLoader property is defined private first in AbstractFactoryBean and then again in AbstractServiceLoaderBasedFactoryBean.Code:<bean id="MyCustomClassLoader" class="my.package.MyCustomClassLoader" scope="singleton" lazy-init="true" /> <bean id="MyServiceLoaderFactoryBean" class="org.springframework.beans.factory.serviceloader.ServiceLoaderFactoryBean" scope="singleton" lazy-init="false"> <property name="serviceType" value="my.package.MyServiceClass"/> <property name="beanClassLoader" ref="MyCustomClassLoader"/> </bean>
I notice in debugger that:
- AbstractAutowireCapableBeanFactory.doCreateBean initially sets both beanClassLoader properties to the default ClassLoader Launcher$AppClassLoader
- It then sets the second beanClassLoader property to MyCustomClassLoader after calling populateBean (good)
- It then calls initializeBean where the second beanClassLoader property gets reset back to the default ClassLoader Launcher$AppClassLoader (bad)
I tried modifying the code so there is only one protected beanClassLoader property in AbstractFactoryBean and no overriding second property of same name in AbstractServiceLoaderBasedFactoryBean. The result is the same - the now single beanClassLoader property in AbstractFactoryBean is unexpectedly reset to the default ClassLoader Launcher$AppClassLoader.
Is this a known issue? ShalI I file an issue? Is there a workaround? Thanks for your help.


Reply With Quote