【转】

解决方法:

http://forum.springsource.org/showthread.php?85016-IllegalArgumentException-with-ApplicationContextAware-Proxy

在配置文件中加入proxy-target-class="true"

<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

或者:

<aop:config proxy-target-class="true">

现在我的配置文件如下:

<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<!-- 配置事务管理器 -->
<bean
id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="sessionFactory" >
<ref local="sessionFactory" />
</property>
</bean>
<!-- 配置哪些方法需要哪些事务 -->
<tx:advice
id="txadvice"
transaction-manager="transactionManager" >
<tx:attributes>
<tx:method
name="create*"
propagation="REQUIRED" />
<tx:method
name="delete*"
propagation="REQUIRED" />
<tx:method
name="update*"
propagation="REQUIRED" />
<tx:method name="read*"
read-only="true"
propagation="NOT_SUPPORTED"/>
<tx:method
name="*"
read-only="true" />
</tx:attributes>
</tx:advice>
<!-- pointcut切入点;advice,通知,即被织入的方法 。这儿是AOP-->
<aop:config proxy-target-class="true">
<aop:pointcut
id="managerMethods"
expression="execution (* org.ccnt.med.dao.TbTopicDao.*(..))" />
<aop:pointcut
id="managerMethods"
expression="execution (* org.ccnt.med.dao.TbDisTopicDao.*(..))" />
<aop:advisor
advice-ref="txadvice"
pointcut-ref="managerMethods" />
</aop:config>

解释:

AOP使用的动态代理可以针对接口,也可以针对类。java的动态代理只能针对接口。

在用Spring的AOP时,默认动态代理是针对接口的,而我用的是针对类的,所以要加上proxy-target-class="true"

Spring AOP报错处理 Can not set field to $Proxy 在spring中使用事物或AOP遇到的错误的更多相关文章

  1. 解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element

    解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element 'beans'.Referenced file conta ...

  2. Spring Boot报错 MultipartException The temporary upload...

    Spring Boot报错:尤其是在处理Ribbon这类接口调用型的负载均衡组件,常见问题 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.se ...

  3. 项目中访问controller报错:HTTP Status 500 - Servlet.init() for servlet spring threw exception

    直接访问controller路径http://localhost:8080/index报错: HTTP Status 500 - Servlet.init() for servlet spring t ...

  4. Spring Boot 报错记录

    Spring Boot 报错记录 由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决 解决方案1: @SpringBootApplication(exclude = Dat ...

  5. Spring.之.报错:Caused by: java.lang.IllegalArgumentException: No Spring Session store is configured: set the 'spring.session.store-type' property

    Spring.之.报错 No Spring Session store is configured springboot在启动的时候报如下错误: Error starting ApplicationC ...

  6. vs2010一运行就报错deven.exe assert failure 解决方法,卸载系统中.netFramework最新版本的(简体中文)

    vs2010一运行就报错deven.exe assert failure 解决方法,卸载系统中.netFramework最新版本的(简体中文)

  7. Spring AOP报错

    八月 01, 2016 10:08:48 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRe ...

  8. Spring AOP 报错org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'XXXXXX' defined in class path resource..........

    完整报错如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'befo ...

  9. spring boot aop 报错

    1.控制台报错 Pointcut is not well-formed: expecting 'name pattern' at character position 33 execution(com ...

随机推荐

  1. DB2 Z/os Load utility 使用

    Use the LOAD online utility to load one or more tables of a table space. The LOAD utility loads reco ...

  2. Django环境配置

    Django安装 #安装最新版本的Django $ pip install django #或者指定安装版本 pip install -v django==1.7.1 项目创建 $ django-ad ...

  3. Cocoapods 更新后 使用

    platform:ios,'8.0'target 'APPNAME' do pod 'SMSSDK' pod 'MBProgressHUD', '0.9.1' pod 'AFNetworking', ...

  4. mysqlbinlog 查看日志时发生报错

    [root@cs Downloads]# mysqlbinlog mysql-bin. ERROR: Error , event_type: ERROR: Could not read entry a ...

  5. eclipse使用tips-Toggle Mark Occurrences 颜色更改

    Toggle Mark Occurrences这个功能非常好用,能把选中的方法/变量在本类中全部出现的地方高亮显示,是一个非常实用的功能.但是默认颜色是灰色,非常毁眼.可以通过下面的设置更改为自己喜欢 ...

  6. 【Java EE 学习 19】【使用过滤器实现全站压缩】【使用ThreadLocal模式解决跨DAO事务回滚问题】

    一.使用过滤器实现全站压缩 1.目标:对网站的所有JSP页面进行页面压缩,减少用户流量的使用.但是对图片和视频不进行压缩,因为图片和视频的压缩率很小,而且处理所需要的服务器资源很大. 2.实现原理: ...

  7. makefile基础(GNU)

    makefile的核心 targets : prerequisites ; commands...   //不分行的情况 targets : prerequisites                 ...

  8. C# SMTP邮件发送 分类: C# 2014-07-13 19:10 334人阅读 评论(1) 收藏

    邮件发送在网站应用程序中经常会用到,包括您现在看到的博客,在添加评论后,系统会自动发送邮件通知到我邮箱的,把系统发送邮件的功能整理了下,做了一个客户端Demo,希望对有需要的童鞋有所帮助: 核心代码: ...

  9. hdu 5833 Zhu and 772002 高斯消元

    Zhu and 772002 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test ...

  10. Java利用Preferences设置个人偏好

    Java利用Preferences设置个人偏好 Preferences的中文意思即偏好或喜好的意思,也就是说同一个程序在每次运行完后,可以通过Preferences来记录用户的偏好,下次启动时,程序会 ...