Spring 异常 Couldn't generate CGLIB subclass of class [class spring.dao.UserDAO]: Common causes of this problem include using a f
来源:互联网 发布:现代远程网络教育 编辑:程序博客网 时间:2024/05/16 08:35
Couldn't generate CGLIB subclass of class [class spring.dao.UserDAO]: Common causes of this problem include using a final class or a non-visible class;
我的一部分配置文件如下:
<!-- 配置UserDAO -->
<bean id="userDAO" class="spring.dao.UserDAO">
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>
<bean id="UserDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="userDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED </prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly </prop>
</props>
</property>
</bean>
ERROR - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UserDAOProxy' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Couldn't generate CGLIB subclass of class [class spring.dao.UserDAO]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
org.springframework.aop.framework.AopConfigException: Couldn't generate CGLIB subclass of class [class spring.dao.UserDAO]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:189)
解决办法:
这个问题是因为使用了代理bean,
在spring中有两种代理CGLIB和JDK代理,理论上来说使用CGLIB可以直接对类进行代理,可是我也没有调出来。(外国一些网站上说是这个包本身有问题,但还是不太明白)
只好使用JDK来实现代理,这样,要代理的目标类必须实现一个接口。然后通过该接口来实现代理。
也就是说为要实现代理的类写一个接口IUserDAO,并且在配置文件的
<bean id="UserDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
中加入
<property name="proxyInterfaces">
<value>spring.dao.IUserDAO</value>
</property>
这样就使用了JDK的代理。也就没有了这个异常,不过……
不过还要再改一个地方不然会出下面这个异常,转换异常,因为现在使用的是接口,而原来是对类的操作,当然报这个异常了。
(Web 项目会出这个异常)Failed to convert property value of type [java.lang.String] to required type [java.lang.Class[]] for property 'proxyInterfaces'; nested exception is java.lang.IllegalArgumentException: Cannot find class [IUserDAO]. Root cause: java.lang.ClassNotFoundException: IUserDAO
(Java Project 会出这个异常) java.lang.ClassCastException: $Proxy0
要在使用这个UserDAOProxy的地方(也就是声明UserDAO的set方法的地方),用接口来new 这个类。如下
IUserDAO userDAO = new UserDAO();
这样就彻底解决这个问题了。
在此要感谢江楼月(网易博客)的指导啊。呵呵
还有流火,
还有许多人
- Spring 异常 Couldn't generate CGLIB subclass of class [class spring.dao.UserDAO]: Common causes of this problem include using a f
- Could not generate CGLIB subclass of class编译时出错
- Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy22]
- org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [c
- description of USB class,subclass and protocol
- spring Cglib is useful but a class @Transactional don't proxy
- generate a simple class for all fields of a table .
- org.springframework.beans.NotWritablePropertyException: Invalid property 'userDao' of bean class
- Spring aop Cannot subclass final class class com.sun.proxy
- this Directory An active use of a class recurse
- org.hibernate.PropertyNotFoundException: Could not find a getter for id in class com.pb.dao.UserDao
- Spring异常:Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
- pesudo-class of <a> element
- Common causes of nans during training
- How can we restrict dynamic allocation of objects of a class using new?
- org.springframework.beans.NotWritablePropertyException: Invalid property 'userDao' of bean class [co
- spring的 object is not an instance of declaring class
- Spring保错:Cannot subclass final class class java.lang.String
- 要写软件项目管理实践报告。。头疼!有人能给点建议吗?
- vi中结合ctag查找函数声明
- 尝试数据库被标记为RESTORING的处理方式
- SysUtils.StrScan、SysUtils.StrRScan、SysUtils.StrPos函数
- mfc工程中添加com接口支持
- Spring 异常 Couldn't generate CGLIB subclass of class [class spring.dao.UserDAO]: Common causes of this problem include using a f
- VB中的字符串操作函数
- 摩托罗拉 W24 WIFI模块 使用 笔记(三)
- C/C++关键字static,const,inline,define,typedef
- 中国的技术论坛
- asp.net中数据链路层的创建(11)
- 系统程序员成长计划-组合的威力(一)
- asp.net中数据链路层的创建(12)
- asp.net中数据链路层的创建(13)