本人使用纯annotation搭建了一个SSH的项目在service层使用Spring如下annotation
@Service
@Scope("prototype")
@Transcational
对service层进行注释,在项目启动和Spring创建Service层实例时会报如下的异常:
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Found finalize() method - using NO_OVERRIDE 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Found 'hashCode' method: public native int java.lang.Object.hashCode() 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Unable to apply any optimisations to advised method: protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Found 'equals' method: public boolean java.lang.Object.equals(java.lang.Object) 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Unable to apply any optimisations to advised method: public java.lang.String java.lang.Object.toString() 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.aopalliance.aop.Advice) 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.springframework.aop.Advisor) 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(int,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setTargetSource(org.springframework.aop.TargetSource) 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isProxyTargetClass() 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setExposeProxy(boolean) 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isExposeProxy() 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isFrozen() 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(int,org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract org.springframework.aop.Advisor[] org.springframework.aop.framework.Advised.getAdvisors() 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract org.springframework.aop.TargetSource org.springframework.aop.framework.Advised.getTargetSource() 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setPreFiltered(boolean) 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isPreFiltered() 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.Class[] org.springframework.aop.framework.Advised.getProxiedInterfaces() 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isInterfaceProxied(java.lang.Class) 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.removeAdvisor(int) throws org.springframework.aop.framework.AopConfigException 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvisor(org.springframework.aop.Advisor) 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.replaceAdvisor(org.springframework.aop.Advisor,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvice(org.aopalliance.aop.Advice) 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.String org.springframework.aop.framework.Advised.toProxyConfigString() 
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.Class org.springframework.aop.TargetClassAware.getTargetClass() 
去掉@Transactional标签就不会报此异常,
我追踪异常到org.springframework.aop.framework.Cglib2AopProxy下的
public Object getProxy(ClassLoader classLoader)方法抛出了此异常,请哪位大仙帮忙解决一下此问题

解决方案 »

  1.   

    我也在玩这个最近,不过没有出现过这个问题。在service中使用注解应该默认用的是jdk的动态代理啊,你这个好像是用cglib,可能还是配置文件配置问题。
      

  2.   

    说明一下我使用的是Spring 3.1 + hibernate 3.3
    spring配置失误控制如下:
     <!-- 事务配置 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean> <!-- 使用annotation定义事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" />
    请问我的配置那里有错了,谢谢
      

  3.   

    坐等3天了,都不见有高手能帮我解决此问题啊!!!!难道CSDN就没有高手吗???????
      

  4.   

    我这几天也遇到了这个问题,后来从网上搜到了解决办法!
    是包的问题---->
    缺少包:cglib-nodep-2.2.jar 
    Java代码  
    1.java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.core.KeyFactory   
    2.java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer  
    java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.core.KeyFactory
    java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancerspring2.5需要使用cglib-nodep-2.2.jar,而不能使用cglib2.2.jar,也可能是因为有多个cglib包引起的冲突。 另附在sf.net上的官方包下载地址: 
    http://sourceforge.net/projects/cglib/files/ (注意下载文件列表中的cglib-nodep-2.2.jar,而不是cglib-2.2.jar) 直接下载地址:http://sourceforge.net/projects/cglib/files/cglib2/2.2/cglib-nodep-2.2.jar/download 原文链接:http://hi.baidu.com/cnkarl/blog/item/bba346be1e5fce0718d81f8c.html 
      

  5.   

    1.cglib包是否是4L说的cglib-nodep-2.2.jar  如果不是请将它删除,添加该jar包
    2.你既然都是用了@service为什么还是用@Transcational?@service注解中就存在@Transcational
      出错原因可能以上带来的问题,原因可能为:
       1.在默认情况下是使用JDK的,但是在以前的JDK中没有很好的处理,因此spring自己写了cglib 但是如果你使用的不是cglib-nodep-2.2.jar   或是cglib.jar 这个包好像是hibernate(具体的不是很清楚)
       2.@service 包含了@Transcational 因此存在两份Transcational。 可能的原因就是有冲突,不知道到底使用哪个Transcational。
     如果我说的不对,请大家赐教!!!!!谢谢!!!!