今天在利用spring框架部署开发项目时, 结果发现弹出一警告框:
cannot Deploy smartservice
Deployment Error for module:
smartservice:
Exception while loading the app :
java.lang.Exception:
java.lang.IllegalStateException:
ContainerBase.addChild: start:
org.apache.catalina.LifecycleException:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘analyzActive’ defined in class >path resource [applicationContext-task.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.
spring xml源码为:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<aop:aspectj-autoproxy />
<context:annotation-config />
<context:component-scan base-package="com.lee" />
<tx:annotation-driven transaction-manager="txManager" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="hkairlines" />
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
</beans>
原因是:
<aop:aspectj-autoproxy />有一个proxy-target-class属性,默认为false,表示使用jdk动态代理织入增强,当配为<aop:aspectj-autoproxy poxy-target-class=”true”/>时,表示使用CGLib动态代理技术织入增强。不过即使proxy-target-class设置为false,如果目标类没有声明接口,则spring将自动使用CGLib动态代理。
方法一: 添加 cglib-nodep-2.2.2.jar 后解决
方法二: 添加接口, 接口实现类, 使用实现类Method解决, 不需添加CGLib