欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SSH下Hibernate事务问题createCriteria is not valid without active transaction

程序员文章站 2022-04-15 18:41:45
...
今天在ssh下又一次遇到事务问题,异常“ createCriteria is not valid without active transaction” 找来找去发现问题在于给hibernate配置中增加了如下属性导致:

<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>


去掉之后可以正常读写数据库了,目前还不知道是什么原因,哪位达人可以帮忙解释一下。

异常如下:

org.hibernate.HibernateException: createCriteria is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:340) ~[hibernate-core-3.5.5-Final.jar:3.5.5-Final]
at $Proxy56.createCriteria(Unknown Source) ~[na:na]
at org.springside.modules.orm.hibernate.SimpleHibernateDao.createCriteria(SimpleHibernateDao.java:289) ~[springside3-core-3.3.4.jar:3.3.4]
at org.springside.modules.orm.hibernate.SimpleHibernateDao.findUniqueBy(SimpleHibernateDao.java:173) ~[springside3-core-3.3.4.jar:3.3.4]
at sms.web.service.AccountManager.findUserByLoginName(AccountManager.java:80) ~[AccountManager.class:na]
at sms.web.service.AccountManager$$FastClassByCGLIB$$9f03f2c8.invoke(<generated>) ~[cglib-nodep-2.2.jar:na]
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) ~[cglib-nodep-2.2.jar:na]
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688) ~[spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) ~[spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) ~[spring-tx-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) ~[spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at sms.web.service.AccountManager$$EnhancerByCGLIB$$f50196f0.findUserByLoginName(<generated>) ~[cglib-nodep-2.2.jar:na]
at sms.web.actions.account.LoginAction$1.execute(LoginAction.java:59) ~[LoginAction$1.class:na]
at base.action.WebSupport.actionExecute(WebSupport.java:228) ~[et-util-1.0-SNAPSHOT.jar:na]
at sms.web.actions.account.LoginAction.execute(LoginAction.java:48) [LoginAction.class:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_23]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_23]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_23]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_23]
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263) [xwork-core-2.2.1.1.jar:2.2.1.1]
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) [struts2-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) [struts2-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) [struts2-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) [struts2-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) [struts2-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) [struts2-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) [xwork-core-2.2.1.1.jar:2.2.1.1]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at sms.web.interceptor.CheckLoginFilter.intercept(CheckLoginFilter.java:79) [CheckLoginFilter.class:na]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at sms.web.interceptor.DebugInterceptor.intercept(DebugInterceptor.java:22) [DebugInterceptor.class:na]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) [xwork-core-2.2.1.1.jar:2.2.1.1]
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) [struts2-core-2.2.1.1.jar:2.2.1.1]
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485) [struts2-core-2.2.1.1.jar:2.2.1.1]
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) [struts2-core-2.2.1.1.jar:2.2.1.1]
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) [struts2-core-2.2.1.1.jar:2.2.1.1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244) [catalina.jar:7.0.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.5]
at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102) [struts2-core-2.2.1.1.jar:2.2.1.1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244) [catalina.jar:7.0.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.5]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244) [catalina.jar:7.0.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.5]
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) [spring-orm-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244) [catalina.jar:7.0.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.5]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) [catalina.jar:7.0.5]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [catalina.jar:7.0.5]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) [catalina.jar:7.0.5]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108) [catalina.jar:7.0.5]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558) [catalina.jar:7.0.5]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) [catalina.jar:7.0.5]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379) [catalina.jar:7.0.5]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243) [tomcat-coyote.jar:7.0.5]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259) [tomcat-coyote.jar:7.0.5]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:237) [tomcat-coyote.jar:7.0.5]
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281) [tomcat-coyote.jar:7.0.5]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_23]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_23]
at java.lang.Thread.run(Thread.java:662) [na:1.6.0_23]


================================
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>et platform</display-name>

<!-- Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用,号分隔
此参数用于后面的Spring Context Loader -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:ctx-jms.xml
classpath:ctx-platform.xml
classpath:ctx-schedule.xml
classpath:ctx-ws.xml
</param-value>
</context-param>


<!-- CXF Servlet 配置 -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>

<!-- Filter 定义 -->
<!-- Character Encoding filter -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<!-- Hibernate Open Session In View filter-->
<filter>
<filter-name>hibernateOpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>

<!-- SpringSecurity filter
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
-->
<!-- Struts2 filter -->
<filter>
<filter-name>struts2CleanupFilter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>struts2Filter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<!-- 下面的filter验证页面session是否已经成功登录-->
<filter-mapping>
<filter-name>hibernateOpenSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>


<filter-mapping>
<filter-name>hibernateOpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>islogin</filter-name>
<filter-class>sms.web.interceptor.CheckLoginFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>islogin</filter-name>
<url-pattern>/pages/*</url-pattern>
</filter-mapping>
<!-- Filter 映射 -->
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!--<filter-mapping>-->
<!--<filter-name>hibernateOpenSessionInViewFilter</filter-name>-->
<!--<url-pattern>/j_spring_security_check</url-pattern>-->
<!--</filter-mapping>-->

<!--<filter-mapping>-->
<!--<filter-name>springSecurityFilterChain</filter-name>-->
<!--<url-pattern>*.action</url-pattern>-->
<!--<dispatcher>REQUEST</dispatcher>-->
<!--<dispatcher>FORWARD</dispatcher>-->
<!--</filter-mapping>-->

<!--<filter-mapping>-->
<!--<filter-name>springSecurityFilterChain</filter-name>-->
<!--<url-pattern>/j_spring_security_check</url-pattern>-->
<!--<dispatcher>REQUEST</dispatcher>-->
<!--<dispatcher>FORWARD</dispatcher>-->
<!--</filter-mapping>-->
<filter-mapping>
<filter-name>struts2CleanupFilter</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>

<filter-mapping>
<filter-name>struts2Filter</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>


<!--Spring的ApplicationContext 载入 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>

<!-- session超时定义,单位为分钟 -->
<session-config>
<session-timeout>20</session-timeout>
</session-config>

<!-- 出错页面定义 -->
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/common_springside/500.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/common_springside/500.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/common_springside/404.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/common_springside/403.jsp</location>
</error-page>
</web-app>



spring 配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd" default-lazy-init="false">

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<!-- 标准配置 -->
<value>classpath*:/ctx-config/db.properties</value>
<!-- 本地开发环境配置 -->
<value>classpath*:/ctx.properties</value>
<!-- 服务器生产环境配置 -->
<value>file:/var/mini-service/application.server.properties</value>
</list>
</property>
</bean>

<bean id="springContextHolder" class="org.springside.modules.utils.spring.SpringContextHolder" lazy-init="false"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"/>
<property name="minPoolSize" value="${c3p0.minPoolSize}"/>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"/>
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"/>
<property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTextPeriod}"/>
<property name="maxStatements" value="${c3p0.maxStatements}"/>
<property name="autoCommitOnClose" value="${c3p0.autoCommitOnClose}"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
[b] <prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>[/b][color=red][/color]
</props>
</property>
<property name="packagesToScan" value="sms.entities" />
</bean>
<!-- 使Spring关注Annotation -->
<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<!-- 事务管理器配置,单数据源事务 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 使Spring关注Annotation -->
<context:annotation-config />
<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<context:component-scan base-package="sms" />


<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager"/>
</bean>
<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<aop:config />
<aop:aspectj-autoproxy />

</beans>