最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

解決Spring JPA 使用@transaction注解時(shí)產(chǎn)生CGLIB代理沖突問題

 更新時(shí)間:2021年08月04日 15:59:29   作者:hikeboy  
這篇文章主要介紹了解決Spring JPA 使用@transaction注解時(shí)產(chǎn)生CGLIB代理沖突問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Spring JPA 使用@transaction注解時(shí)產(chǎn)生CGLIB代理沖突

在使用JPA進(jìn)行數(shù)據(jù)庫的刪除操作時(shí)需要使用@Transactional注解來支持事物:

 @Modifying
    @Transactional
    @Query(" delete from FollowerInfo " +
            " where crmAuth = :crmAuth and investUserId = :invUserId")
    void deleteByCrmAuthAndInvUserId(@Param("crmAuth") String crmAuth, @Param("invUserId") Long invUserId);

但是,在添加了如上方法后,測(cè)試服務(wù)啟動(dòng)失敗。

查看日志報(bào)錯(cuò)如下:

Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy52
	at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
	at org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
	at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
	at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
	at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
	at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
	at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57)
	at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:202)
	... 38 more
[2017-02-09 10:56:33 ERROR] [localhost-startStop-1] (org.springframework.web.context.ContextLoader:331) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adviserCommFollowerServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ounersc.ic.adviser.repository.community.AdviserCommFollowerRepository com.ounersc.ic.adviser.service.impl.AdviserCommFollowerServiceImpl.adviserCommFollowerRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adviserCommFollowerRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy52]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy52
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1204)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4738)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ounersc.ic.adviser.repository.community.AdviserCommFollowerRepository com.ounersc.ic.adviser.service.impl.AdviserCommFollowerServiceImpl.adviserCommFollowerRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adviserCommFollowerRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy52]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy52
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:555)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
	... 22 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adviserCommFollowerRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy52]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy52
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:116)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1512)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:313)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1081)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1006)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:904)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:527)
	... 24 more
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy52]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy52
	at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:212)
	at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:109)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:445)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:331)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:291)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1713)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:113)
	... 31 more
Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy52
	at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
	at org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
	at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
	at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
	at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
	at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
	at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57)
	at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:202)
	... 38 more
09-Feb-2017 10:56:33.145 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
09-Feb-2017 10:56:33.145 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors

org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy52]: Common causes of this problem include using a final class or a non-visible class

對(duì)于此異常,這篇帖子中講到了產(chǎn)生該異常的原因,但是未給出解決辦法。

http://stackoverflow.com/questions/20063320/springmvc-proxy-issue

簡單來說,原因主要是代理沖突:Spring 早期的版本,要用com.sun.proxy的代理 ,而 jpa如果加了@transaction 注解后 需要用CGLIB的代理

因此產(chǎn)生了沖突

解決辦法:

Spring 已經(jīng)在高版本中修復(fù)了該問題,把Spring從4.0升級(jí)到4.2.5后,問題解決:

在pom.xml加入:

   <properties>
        <spring.framework.version>4.2.5.RELEASE</spring.framework.version>
    </properties>

Spring 啟用CGLIB解決事物代理失敗

問題描述:

接口A提供公用的CRUD 操作,抽象類B實(shí)現(xiàn)接口A,接口C提供各模型特有的相關(guān)數(shù)據(jù)庫操作。

類D繼承抽象類B實(shí)現(xiàn)接口C如果使用JDK動(dòng)態(tài)代理,Spring會(huì)將類D向上轉(zhuǎn)型為接口C,那么在使用中必須注入接口A。

如果注入類D的類型。會(huì)報(bào)錯(cuò)說代理類型XX無法轉(zhuǎn)換為類D的類型。

解決辦法如下:

<bean id="transactionManagerCMS"
  class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  <property name="sessionFactory" ref="mySessionFactory" />
  <property name="dataSource" ref="dataSourceCMS" />
 </bean>
 <!-- the transactional advice (what 'happens'; see the <aop:advisor/> bean
  below) -->
 <tx:advice id="txAdvice" transaction-manager="transactionManagerCMS">
  <!-- the transactional semantics... -->
  <tx:attributes>
   <tx:method name="*" />
  </tx:attributes>
 </tx:advice>
 <!-- ensure that the above transactional advice runs for any execution of
  an operation defined by the FooService interface -->
 <aop:config proxy-target-class="true">
  <aop:pointcut id="fooServiceOperation"
   expression="execution(* com.harvest.smartHotels.info.dao.serviceContent.interfaces.*.*(..))" />
  <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation" />
 </aop:config>

動(dòng)態(tài)代理使用CGLIB,這樣注入類型就可以使類D。

相關(guān)文章

  • Springmvc數(shù)據(jù)回顯實(shí)現(xiàn)原理實(shí)例解析

    Springmvc數(shù)據(jù)回顯實(shí)現(xiàn)原理實(shí)例解析

    這篇文章主要介紹了Springmvc數(shù)據(jù)回顯實(shí)現(xiàn)原理實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • MyBatis實(shí)現(xiàn)簡單的數(shù)據(jù)表分月存儲(chǔ)

    MyBatis實(shí)現(xiàn)簡單的數(shù)據(jù)表分月存儲(chǔ)

    本文主要介紹了MyBatis實(shí)現(xiàn)簡單的數(shù)據(jù)表分月存儲(chǔ),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • 淺談PrintStream和PrintWriter的區(qū)別和聯(lián)系

    淺談PrintStream和PrintWriter的區(qū)別和聯(lián)系

    這篇文章主要介紹了淺談PrintStream和PrintWriter的區(qū)別和聯(lián)系,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • Java StringBuilder類原理及常用方法

    Java StringBuilder類原理及常用方法

    這篇文章主要介紹了Java StringBuilder類原理及常用方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-12-12
  • java多線程之Phaser的使用詳解

    java多線程之Phaser的使用詳解

    這篇文章主要介紹了java多線程之Phaser的使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • python實(shí)現(xiàn)高斯模糊及原理詳解

    python實(shí)現(xiàn)高斯模糊及原理詳解

    高斯模糊是一種常見的模糊技術(shù),本文主要介紹了python實(shí)現(xiàn)高斯模糊及原理詳解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • java 如何給對(duì)象中的包裝類設(shè)置默認(rèn)值

    java 如何給對(duì)象中的包裝類設(shè)置默認(rèn)值

    這篇文章主要介紹了java 如何給對(duì)象中的包裝類設(shè)置默認(rèn)值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • Java基礎(chǔ)之static關(guān)鍵字的使用講解

    Java基礎(chǔ)之static關(guān)鍵字的使用講解

    這篇文章主要介紹了Java基礎(chǔ)之static關(guān)鍵字的使用講解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • SpringBoot整合jasypt進(jìn)行重要數(shù)據(jù)加密的操作代碼

    SpringBoot整合jasypt進(jìn)行重要數(shù)據(jù)加密的操作代碼

    Jasypt(Java?Simplified?Encryption)是一個(gè)專注于簡化Java加密操作的開源工具,它提供了一種簡單而強(qiáng)大的方式來處理數(shù)據(jù)的加密和解密,使開發(fā)者能夠輕松地保護(hù)應(yīng)用程序中的敏感信息,本文給大家介紹了SpringBoot整合jasypt進(jìn)行重要數(shù)據(jù)加密,需要的朋友可以參考下
    2024-05-05
  • Spring注解@Configuration和@Component區(qū)別詳解

    Spring注解@Configuration和@Component區(qū)別詳解

    @Component和@Configuration都可以作為配置類,之前一直都沒覺得這兩個(gè)用起來有什么差別,可能有時(shí)程序跑的和自己想的有所區(qū)別也沒注意到,下面這篇文章主要給大家介紹了關(guān)于Spring注解@Configuration和@Component區(qū)別的相關(guān)資料,需要的朋友可以參考下
    2023-04-04

最新評(píng)論

宽甸| 桐乡市| 德阳市| 平顺县| 苍南县| 东阿县| 旬邑县| 大方县| 林州市| 乌拉特前旗| 石城县| 天全县| 霍山县| 济阳县| 清丰县| 汝南县| 棋牌| 灵丘县| 溧阳市| 将乐县| 顺昌县| 策勒县| 岢岚县| 丰都县| 松阳县| 屏东县| 疏勒县| 北安市| 岳普湖县| 石柱| 洛浦县| 大连市| 拉孜县| 闵行区| 苗栗市| 梧州市| 绥棱县| 微山县| 新和县| 阳原县| 茂名市|