CGLIB proxy error after spring bean definition loading into XmlWebApplicationContext at runtime

Posted by VasylV on Stack Overflow See other posts from Stack Overflow or by VasylV
Published on 2010-04-23T13:56:34Z Indexed on 2010/04/26 8:03 UTC
Read the original article Hit count: 288

Filed under:
|
|
|

I load additional singleton beans definitions at runtime from external jar file into existing XmlWebApplicationContext of my application:


BeanFactory beanFactory = xmlWebApplicationContext.getBeanFactory();
DefaultListableBeanFactory defaultFactory = (DefaultListableBeanFactory)beanFactory;
final URL url = new URL("external.jar");
final URL[] urls = {url};
ClassLoader loader = new URLClassLoader(urls, this.getClass().getClassLoader());
defaultFactory.setBeanClassLoader(loader);
final ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(defaultFactory);
final DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
resourceLoader.setClassLoader(loader);
scanner.setResourceLoader(resourceLoader);
scanner.scan("com.*");
Object bean = xmlWebApplicationContext.getBean("externalBean");


After all above xmlWebApplicationContext contains all external definitions of beans. But when i am trying to get bean from context exception is thrown:

Couldn't generate CGLIB proxy for class ...

I saw in debug mode that in the bean initialization process first time proxy is generated by org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator

and than it is tried to generate proxy with org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator

but fails with mentioned exception.

© Stack Overflow or respective owner

Related posts about java

Related posts about spring