spring配置 no matching editors or conversion strategy found 异常解决方案
来源:互联网 发布:苏州经济数据 编辑:程序博客网 时间:2024/05/21 22:31
spring 配置中遇到该问题,可以通过注入的方式解决,代码如下:
<tx:annotation-driven transaction-manager="myTxManager" proxy-target-class="true"/>
总结:Spring注入的是接口,关联的是实现类。 这里注入了实现类,所以报异常了。
另外一种方法:
由于默认是注入接口。所以
在Spring的配置文件中在<aop:config></aop:config>中加入“proxy-target-class="true" ”,表示可以用类注入,即:
<aop:config proxy-target-class="true"></aop:config>
<aop:config proxy-target-class="true">
<aop:pointcut id="daoOperation" expression="execution(* com.yg.ordertiket.dao.*.*(..))"/>
<aop:advisor advice-ref="txManager" pointcut-ref="daoOperation"/>
</aop:config>
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
错误原因:
OpenSessionInViewFilter在getSession的时候,会把获取回来的session的flush mode 设为FlushMode.NEVER。然后把该sessionFactory绑定到TransactionSynchronizationManager,使request的整个过程都使用同一个session,在请求过后再接除该sessionFactory的绑定,最后closeSessionIfNecessary根据该session是否已和transaction绑定来决定是否关闭session。在这个过程中,若HibernateTemplate 发现自当前session有不是readOnly的transaction,就会获取到FlushMode.AUTO Session,使方法拥有写权限。
也即是,如果有不是readOnly的transaction就可以由Flush.NEVER转为Flush.AUTO,拥有insert,update,delete操作权限,如果没有transaction,并且没有另外人为地设flush model的话,则doFilter的整个过程都是Flush.NEVER。所以受transaction保护的方法有写权限,没受保护的则没有。
解决办法:
采用spring的事务声明,使方法受transaction控制
<bean id="baseTransaction"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager"/>
<property name="proxyTargetClass" value="true"/>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
//采用 log4j来完成调试时的日志功能
private static Log log = LogFactory.getLog(NewsDAOHibernate.class);
//以私有的成员变量来保存 SessionFactory。
private SessionFactory sessionFactory;
//以私有变量的方式保存 HibernateTemplate
private HibernateTemplate hibernateTemplate = null;
//设值注入 SessionFactory必需的 setter方法
- spring配置 no matching editors or conversion strategy found 异常解决方案
- spring配置 no matching editors or conversion strategy found 异常解决方案
- spring配置 no matching editors or conversion strategy found 异常解决方案
- no matching editors or conversion strategy found 异常
- no matching editors or conversion strategy found 异常_解决办法
- spring报no matching editors or conversion strategy found
- 解决: Spring no matching editors or conversion strategy found
- no matching editors or conversion strategy found
- no matching editors or conversion strategy found
- no matching editors or conversion strategy found
- no matching editors or conversion strategy found
- no matching editors or conversion strategy found
- No Matching editors or conversion strategy found
- spring java.lang.IllegalArgumentException:。。。 no matching editors or conversion strategy found异常
- spring 事务配置 no matching editors or conversion strategy
- no matching editors or conversion strategy found 的解决办法
- 项目中遇到 no matching editors or conversion strategy found
- Spring中的报错:no matching editors or conversion strategy found
- 如何通过字符串指定的窗口名称,获取该窗口内的控件
- spring中获取datasource
- Android的framework层是如何对铃声的音量进行调整的
- oracle中去掉文本中的换行符、回车符、制表符小结
- public,protected,private
- spring配置 no matching editors or conversion strategy found 异常解决方案
- Rococo terminator ( 有过很多考虑,很多取舍,目前维持这种状态)
- 卓越软件测试质量体系最佳实践
- 基于角色-功能-资源的权限控制模型的设计与实现
- Android滑动手势侦测方法
- 三星D508,E258,D608用蓝牙传JAVA游戏的方法已经掌握~有弄不明白的朋友可以问我,愿意效劳~
- Python 入门(1)——安装和hello world
- 职业转向
- 关于ScrollPane的update和RefreshPane方法的区别。