SSH框架中applicationContext.xml理解

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

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/atm"/>
<property name="user" value="root"/>
<property name="password" value="225922"/>
<property name="maxPoolSize" value="40"/>
<property name="minPoolSize" value="1"/>
<property name="initialPoolSize" value="1"/>
<property name="maxIdleTime" value="20"/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>

<property name="mappingResources">
<list>
<value>org/atm/po/Customer.hbm.xml</value>
<value>org/atm/po/Card.hbm.xml</value>
<value>org/atm/po/CardType.hbm.xml</value>
<value>org/atm/po/CardLog.hbm.xml</value>
<value>org/atm/po/Bank.hbm.xml</value>
<value>org/atm/po/Atm.hbm.xml</value>
<value>org/atm/po/AtmLog.hbm.xml</value>
</list>
</property>

<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=true
</value>
</property>
</bean>



<bean id="daoTemplate" abstract="true" lazy-init="true" >
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="customerDao" class="org.atm.dao.impl.CustomerDaoImpl" parent="daoTemplate"/>
<bean id="cardDao"     class="org.atm.dao.impl.CardDaoImpl"     parent="daoTemplate"/>
<bean id="cardtypeDao" class="org.atm.dao.impl.CardTypeDaoImpl" parent="daoTemplate"/>
<bean id="cardlogDao"   class="org.atm.dao.impl.CardLogDaoImpl" parent="daoTemplate"/>
<bean id="bankDao"     class="org.atm.dao.impl.BankDaoImpl" parent="daoTemplate"/>
<bean id="atmDao"     class="org.atm.dao.impl.AtmDaoImpl"      parent="daoTemplate"/>
<bean id="bankemployeeDao"     class="org.atm.dao.impl.BankEmployeeDaoImpl"      parent="daoTemplate"/>
<bean id="atmlogDao" class="org.atm.dao.impl.AtmLogDaoImpl" parent="daoTemplate"/>


<bean id="serviceTemplate" abstract="true" lazy-init="true">
<property name="customerDao" ref="customerDao"/>
<property name="cardDao" ref="cardDao"/>
<property name="cardtypeDao" ref="cardtypeDao"/>
<property name="cardlogDao" ref="cardlogDao"/>
<property name="bankDao" ref="bankDao"/>
<property name="atmDao" ref="atmDao"/>
<property name="bankemployeeDao" ref="bankemployeeDao"/>
<property name="atmlogDao" ref="atmlogDao"/>
</bean>

<bean id="atmService" class="org.atm.service.impl.AtmServiceImpl" parent="serviceTemplate"/>
    <bean id="bankEmployeeService" class="org.atm.service.impl.BankEmployeeServiceImpl" parent="serviceTemplate"/>


<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" />
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="leePointcut" expression="bean(atmService)||bean(bankEmployeeService)"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="leePointcut"/>
</aop:config>

</beans>

这时SSH框架的spring配置文件部分,可以看到,首先配置数据源,有了数据源,就可以产生sessionFactory,因此sessionFactory的配置紧随其后,而每个dao层都需要一个sessionFactory,因此接下来配置dao层,参数为sessionFactory,接下来将dao层作为参数配置业务逻辑层。最后对业务逻辑层进行事务管理。
自此,ssh框架的spring配置文件部分完毕。

猜你喜欢

转载自yizhenn.iteye.com/blog/2086186
今日推荐