datasource 配置:
<!-- c3p0 dataSource -->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass">
<value>${jdbc.driverClassName}</value>
</property>
<property name="jdbcUrl">
<value>${jdbc.url}</value>
</property>
<property name="properties">
<props>
<prop key="user">${jdbc.username}</prop>
<prop key="driverClass">${jdbc.driverClassName}</prop>
<prop key="jdbcUrl">${jdbc.url}</prop>
<prop key="password">${jdbc.password}</prop>
<prop key="maxIdleTime">3600</prop>
<prop key="automaticTestTable">c3p0_test_table</prop>
<prop key="idleConnectionTestPeriod">300</prop>
<prop key="minPoolSize">5</prop>
<prop key="maxPoolSize">100</prop>
<prop key="SetBigStringTryClob">true</prop>
<prop key="defaultNChar">true</prop>
</props>
</property>
</bean>
<!-- dbcp dataSource -->
<!--
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
<property name="maxActive">
<value>50</value>
</property>
<property name="maxIdle">
<value>30</value>
</property>
<property name="maxWait">
<value>10000</value>
</property>
</bean>
-->
sessionFactory 配置:
<!-- Hibernate SessionFactory -->
<bean id="hibernateProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.query.substitutions">
true 'T', false 'F'
</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
<prop key="hibernate.generate_statistics">false</prop>
<prop key="hibernate.cache.use_structured_entries">
true
</prop>
<prop key="hibernate.hbm2ddl.auto">
${hibernate.hbm2ddl}
</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
</props>
</property>
</bean>
<bean id="lobHandler"
class="org.springframework.jdbc.support.lob.DefaultLobHandler"
lazy-init="true" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="lobHandler" ref="lobHandler"></property>
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<!--
<value>
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.use_sql_comment=false
hibernate.dialect=${hibernate.dialect}
hibernate.query.substitutions=true 'Y', false 'N'
hibernate.hbm2ddl.auto=${hibernate.hbm2ddl}
hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
</value>
-->
<ref bean="hibernateProperties" />
</property>
<property name="mappingResources">
<list>
<value>local.hbm.xml</value>
<value>filters.hbm.xml</value>
<value>user.hbm.xml</value>
<value>errorlog.hbm.xml</value>
<value>form.hbm.xml</value>
<value>theme.hbm.xml</value>
<value>formAnswer.hbm.xml</value>
<value>audit.hbm.xml</value>
<value>userGroup.hbm.xml</value>
<value>appSettings.hbm.xml</value>
<value>intimateConfiguration.hbm.xml</value>
<value>questionLibrary.hbm.xml</value>
</list>
</property>
</bean>
Transaction 配置:
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config>
<aop:pointcut id="userServiceMethods"
expression="execution(* com.radicasys.lm.service.UserService.*(..))" />
<aop:pointcut id="formServiceMethods"
expression="execution(* com.radicasys.lm.service.FormService.*(..))" />
<aop:pointcut id="ThemeServiceMethods"
expression="execution(* com.radicasys.signup.theme.service.ThemeService.*(..))" />
<aop:pointcut id="auditLogServiceMethods"
expression="execution(* com.radicasys.lm.service.AuditLogService.*(..))" />
<aop:pointcut id="intimateUpdateQueueMethods"
expression="execution(* com.radicasys.lm.intimate.queue.IntimateUpdateQueue.*(..))" />
<aop:pointcut id="localServiceMethods"
expression="execution(* com.radicasys.lm.locale.service.LocalService.*(..))" />
<aop:pointcut id="questionLibraryServiceMethods"
expression="execution(* com.radicasys.lm.service.QuestionLibraryService.*(..))" />
<aop:pointcut id="reportServiceMethods"
expression="execution(* com.radicasys.lm.responses.service.ReportService.*(..))" />
<aop:pointcut id="collectorServiceMethods"
expression="execution(* com.radicasys.lm.responses.service.CollectorService.*(..))" />
<aop:pointcut id="dashboardServiceMethods"
expression="execution(* com.radicasys.lm.service.DashboardService.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="userServiceMethods" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="collectorServiceMethods" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="formServiceMethods" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="ThemeServiceMethods" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="auditLogServiceMethods" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="intimateUpdateQueueMethods" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="localServiceMethods" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="questionLibraryServiceMethods" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="dashboardServiceMethods" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="reportServiceMethods" />
</aop:config>
<!-- Enable @Transactional support 这里因为使用transactionManager名字 所以不用在tx:annotation-driven 加上tx:annotation-driven属性定义-->
<tx:annotation-driven />
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRES_NEW" />
</tx:attributes>
</tx:advice>