1. 程式人生 > >SSH專案整合步驟

SSH專案整合步驟

<?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:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

<!-- 引入db.properties -->
<context:property-placeholder location="classpath:db.properties"/>


<!-- 配置資料來源:配置資料庫連線池c3p0 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${uname}"></property>
<property name="password" value="${upass}"></property>
<property name="jdbcUrl" value="${url}"></property>
<property name="driverClass" value="${driverClass}"></property>

<property name="initialPoolSize" value="${initPoolSize}"></property>
<property name="maxPoolSize" value="${maxPoolSize}"></property>
</bean>

<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- 引入資料來源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 載入hibernate配置檔案 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- 載入對映檔案 -->
<property name="mappingLocations" value="classpath:com/zking/entity/*.hbm.xml"></property>
</bean>


<!-- 配置事務管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 配置事務的屬性 -->
<tx:advice id="myAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>

<!-- 配置事務的切點 -->
<aop:config>
<aop:pointcut expression="execution(* com.zking.dao.*.*(..))" id="myPoint"/>
<aop:advisor advice-ref="myAdvice" pointcut-ref="myPoint"/>
</aop:config>


</beans>