事务配置语句:
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 开启事务控制的注解支持 -->
<tx:annotation-driven transaction-manager="txManager"/>
上述事务配置语句所放的文件位置以web.xml中DispatcherServlet配置的文件为准,否则无法生效
<servlet>
<servlet-name>contacts</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<!--<param-value>/WEB-INF/classes/spring-mvc-servlet.xml</param-value>-->
<param-value>/WEB-INF/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
我配置的是spring-mvc.xml 就放在spring-mvc.xml 中
配置不正确我遇到报错:
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread