浏览 3028 次
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2007-03-29
<!-- ************************************* 以下定义的是系统中的数据源,class 属性定义了连接数据源的类的路径 <property> 标签定义的是 hibernate 数据源文件的路径 ************************************* --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>/WEB-INF/classes/hibernate.cfg.xml</value> </property> </bean> <!-- ************************************* 以下定义了 Spring 所提供的 hibernate3 的事务管理器, 该事务管理器采用设值注入的方式使用了 sessionFactory 定义的数据源 ************************************* --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager"/> <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> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <value>UserServiceImpl</value> </property> <property name="interceptorNames"> <list> <value>transactionInterceptor</value> <!--此处增加新的Interceptor --> </list> </property> </bean> <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"> <property name="transactionInterceptor" ref="transactionInterceptor"/> </bean> <bean id="UserServiceImpl" class="service.UserServiceImpl" autowire="byName" /> <!-- ************************************* 以下 bean 定义了 Spring 的 HibernateTemplate, 当需要在程序中直接对持久化层进行访问时, 可以直接使用 Spring 提供的 HibernateTemplate 类进行操作 ************************************* --> <bean id="infoMsgsDAO" class="dao.InfoMsgsDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!-- Ajax --> <bean name="/ajax" class="struts.action.advinfo.AjaxAction"> <property name="userServiceImpl"> <ref bean="UserServiceImpl"/> </property> </bean> 这是 UserServiceImpl 代码 import dao.InfoContextlistDAO; import dao.InfoFeedbackDAO; import dao.InfoMsgsDAO; public class UserServiceImpl implements IUserService { private InfoContextlistDAO infoContextlistDAO; private InfoFeedbackDAO infoFeedbackDAO; private InfoMsgsDAO infoMsgsDAO; public void setInfoContextlistDAO(InfoContextlistDAO infoContextlistDAO){ this.infoContextlistDAO = infoContextlistDAO; } public InfoContextlistDAO getInfoContextlistDAO(){ return this.infoContextlistDAO; } public void setInfoFeedbackDAO(InfoFeedbackDAO infoFeedbackDAO){ this.infoFeedbackDAO = infoFeedbackDAO; } public InfoFeedbackDAO getInfoFeedbackDAO(){ return this.infoFeedbackDAO; } public void setInfoMsgsDAO(InfoMsgsDAO infoMsgsDAO){ this.infoMsgsDAO = infoMsgsDAO; } public InfoMsgsDAO getInfoMsgsDAO(){ return this.infoMsgsDAO; } } 这是 UserServiceImpl 的接口 IUserService package service; import dao.InfoContextlistDAO; import dao.InfoFeedbackDAO; import dao.InfoMsgsDAO; public interface IUserService { public void setInfoContextlistDAO(InfoContextlistDAO infoContextlistDAO); public InfoContextlistDAO getInfoContextlistDAO(); public void setInfoFeedbackDAO(InfoFeedbackDAO infoFeedbackDAO); public InfoFeedbackDAO getInfoFeedbackDAO(); public void setInfoMsgsDAO(InfoMsgsDAO infoMsgsDAO); public InfoMsgsDAO getInfoMsgsDAO(); } 按道理事务也配置成功了,可是为什么还是报这个错误: javax.servlet.ServletException: 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 org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414) javax.servlet.http.HttpServlet.service(HttpServlet.java:690) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) filter.MemberLimitFilter.doFilter(MemberLimitFilter.java:53) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:75) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77) org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77) 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |