<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- Auto scan base packet 自動掃描所有包-->
<context:component-scan base-package="com" />
<!-- JDBC Config 導入配置有連接配接資料庫參數值配置檔案-->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<!-- DataSource Configuration 配置連接配接資料庫的資料源-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass">
<value>${hbm.driver}</value>
</property>
<property name="jdbcUrl">
<value>${hbm.url}</value>
</property>
<property name="user">
<value>${hbm.user}</value>
</property>
<property name="password">
<value>${hbm.password}</value>
</property>
</bean>
<!-- SessionFactory 建立session工廠-->
<bean id="sessionFacoty"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- 自動建立實體類與資料表之間的映射-->
<property name="packagesToScan">
<list>
<value>com.dns.dto.</value>
</list>
</property>
<!-- 配置方言,控制台輸出格式-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">${hbm.showsql}</prop>
<prop key="hibernate.format_sql">${hbm.formatsql}</prop>
<prop key="hibernate.dialect">${hbm.dialect}</prop>
<!-- 将目前的session上下文交給spring來控制管理-->
<prop key="hibernate.current_session_context_class">
org.springframework.orm.hibernate4.SpringSessionContxt
</prop>
<!-- 是否向資料庫中繼資料設定預設值-->
<prop key="hibernate.temp_use_jdbc_metadata_defaults">false</prop>
</props>
</property>
</bean>
<!-- Transaction Configuration 配置事務管理器-->
<bean id="transactinManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFacoty"></property>
</bean>
<!-- 将配置有@Transactional的方法納入事務管理-->
<tx:annotation-driver transaction-manager="transactionManager"></tx>
<!-- 自動為spring容器中那些配置@aspectj切面的bean建立代理,植入切面-->
<aop:aspectj-autoproxy />
</beans>