Spring AOP: Cannot proxy target class because CGLIB2 is not available

2 respostas
JhowTroMundo

Olá, pessoal.

Estou estudando AOP com Spring, mas o erro descrito no titulo ocorre quando tento rodar o projeto.

Segue meu applicationContext:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
	<bean id="computadorBean" class="br.com.springtest.Computador" autowire="byType" />
	<bean id="impressoraBean" class="br.com.springtest.Impressora" autowire="byType" />
	<bean id="tecladoBean" class="br.com.springtest.Teclado" autowire="byType" />
	<bean id="monitorBean" class="br.com.springtest.Monitor" autowire="byType" />
	
	
	<bean id="gerenciadorArquivosTarget" class="br.com.springtest.GerenciadorArquivos"/>
	
	<bean id="gerenciadorArquivos" class="org.springframework.aop.framework.ProxyFactoryBean">
		<property name="interceptorNames">
			<value>log</value>
		</property>
		
		<property name = "target" ref = "gerenciadorArquivosTarget"/>
	</bean>
	
	<bean id="log" class = "br.com.springtest.log.Log"/>
	
	<bean id="geradorArquivo" class="br.com.springtest.GeradorArquivo" autowire="byName">
		<property name = "gerenciadorArquivos" ref = "gerenciadorArquivos"/>
	</bean>
	
</beans>

Exceção:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'computadorBean' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geradorArquivo' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'gerenciadorArquivos' while setting bean property 'gerenciadorArquivos'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gerenciadorArquivos' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'geradorArquivo' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'gerenciadorArquivos' while setting bean property 'gerenciadorArquivos'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gerenciadorArquivos' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gerenciadorArquivos' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
Caused by: org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
	at org.springframework.aop.framework.DefaultAopProxyFactory.createAopProxy(DefaultAopProxyFactory.java:72)
	at org.springframework.aop.framework.AdvisedSupport.createAopProxy(AdvisedSupport.java:484)
	at org.springframework.aop.framework.ProxyFactoryBean.getSingletonInstance(ProxyFactoryBean.java:256)
	at org.springframework.aop.framework.ProxyFactoryBean.setBeanFactory(ProxyFactoryBean.java:220)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1163)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:267)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1100)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:372)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:919)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:834)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:291)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
	at br.com.springtest.Main.main(Main.java:8)

Tenho os seguintes jars no classpath:

commons-logging-1.0.4.jar
jog4j-1.2.11.jar
spring-aop.jar
spring-beans.jar
spring-context.jar
spring-core.jar
spring-dao.jar
spring-hibernate.jar
spring-jdbc.jar
spring-orm.jar

Não sei o que é esse CGLIB2 referido na exceção, e a apostila que estou usando não o menciona. Também não tenho acesso à web para pesquisa, somente o GUJ.

Obrigado por qualquer ajuda.

2 Respostas

JhowTroMundo

Ninguém?

R

creio que vc precisa do jar do cglib no projeto.

Criado 2 de maio de 2012
Ultima resposta 8 de mai. de 2012
Respostas 2
Participantes 2