spring典型配备完整实例

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: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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd ">
<!-- 分散配置 -->
<context:property-placeholder
location="classpath:jdbc.properties" />
<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="jdbcUrl" value="${jdbcUrl}"></property>

<property name="maxPoolSize" value="5"></property>
<property name="minPoolSize" value="2"></property>
<property name="initialPoolSize" value="2"></property>
<property name="acquireIncrement" value="2"></property>
</bean>
<!-- 配置本地会话工厂bean :整合hibernate资源的核心入口-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- hibernate属性集 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
<!-- 映射资源集 -->
<property name="mappingDirectoryLocations">
<value>classpath:cn/itcast/ssh/domain</value>
</property>
</bean>
<!-- 配置基于会话工厂的DAO -->
<bean id="PersonDaoImpl3SessionFactory"
class="cn.itcast.ssh.dao.impl.PersonDaoImpl3SessionFactory">
<property name="sf" ref="sessionFactory"></property>
</bean>
<!-- *****************业务层面上声明式事务管理: 事务管理配置 ***************** -->
<!-- 配置基于会话工厂的hibernate事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 事务实现类对象属性注入 -->
<bean id="personService" class="cn.itcast.ssh.service.impl.PersonServicePojoXml">
<property name="pd" ref="PersonDaoImpl3SessionFactory"></property>
</bean>
<!-- 定义通知: 方法应用策略: 即什么方法上应用什么事务策略 -->
<tx:advice transaction-manager="transactionManager" id="txadvice">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>
<tx:method name="load*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>
<tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true"/>
<tx:method name="*" propagation="REQUIRED" isolation="DEFAULT"/>
</tx:attributes>
</tx:advice>
<!-- 配置切入点通知组合体 -->
<aop:config><!-- 切入点:  应用通知的地点-->
<aop:pointcut expression="execution(* *..*Service.*(..))" id="txpct"/>
<!-- 切入点上应用的通知 : -->
<aop:advisor advice-ref="txadvice" pointcut-ref="txpct"/>
</aop:config>

</beans>

//*..表示所有包以及所有包下的子包. 用法 *..*Service.*(..)