近来做了一个小项目,用到了Struts1.x,Spring 2.5和Hibernate3,其中的一些配置文件较为典型,所以拿到这里来和大家分享。
- <?xmlversion="1.0"encoding="UTF-8"?>
- <beansxmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsd
- http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
- <!--
- ======================集成Hibernate,配置SessionFactory和数据源======================
- -->
- <!--数据源由Hibernate配置-->
- <beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <propertyname="configLocation">
- <value>classpath:hibernate.cfg.xml</value>
- </property>
- </bean>
- <!--数据源交给Spring配置
- <beanid="dataSource"class="org.springframework.jndi.JndiObjectFactoryBean">
- <propertyname="jndiName"value="jdbc/st"/>
- </bean>
- <beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <propertyname="dataSource"ref="dataSource"/>
- <propertyname="mappingResources">
- <list>
- <value>edu/st/persistence/User.hbm.xml</value>
- <value>edu/st/persistence/News.hbm.xml</value>
- <value>edu/st/persistence/DownFile.hbm.xml</value>
- </list>
- </property>
- <propertyname="hibernateProperties">
- <props>
- <propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
- <propkey="hibernate.show_sql">true</prop>
- <propkey="hibernate.hbm2ddl.auto">update</prop>
- </props>
- </property>
- </bean>
- -->
- <!--
- ===========================配置事务支持======================================
- -->
- <!--配置事务管理器-->
- <beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <propertyname="sessionFactory">
- <refbean="sessionFactory"/>
- </property>
- </bean>
- <!--配置事务的传播特性-->
- <tx:adviceid="txAdvice"transaction-manager="transactionManager">
- <tx:attributes>
- <tx:methodname="add"propagation="REQUIRED"/>
- <tx:methodname="delete"propagation="REQUIRED"/>
- <tx:methodname="update"propagation="REQUIRED"/>
- <tx:methodname="*"read-only="true"/>
- </tx:attributes>
- </tx:advice>
- <!--那些类的哪些方法参与事务-->
- <aop:config>
- <aop:pointcutid="allManagerMethod"expression="execution(*org.scorpio.business.*.*(..))"/>
- <aop:advisorpointcut-ref="allManagerMethod"advice-ref="txAdvice"/>
- </aop:config>
- <!--
- ===========================DAO层组件配置====================================
- -->
- <beanid="userDAO"class="org.scorpio.dao.UserDAOImpl">
- <propertyname="sessionFactory"ref="sessionFactory"/>
- </bean>
- <beanid="managerDAO"class="org.scorpio.dao.ManagerImpl">
- <propertyname="sessionFactory"ref="sessionFactory"/>
- </bean>
- <!--
- ==========================业务逻辑层组件配置=================================
- -->
- <beanid="userService"class="org.scorpio.business.UserServiceImpl">
- <propertyname="userDAO"ref="userDAO"/>
- </bean>
- <beanid="managerService"class="org.scorpio.business.ManagerServiceImpl">
- <propertyname="managerDAO"ref="managerDAO"/>
- </bean>
- <!--
- ======================集成Struts,web层的Action配置==========================
- -->
- <beanname="/userAction"class="org.scorpio.web.action.UserAction">
- <propertyname="userService"ref="userService"/>
- </bean>
- <beanname="/managerAction"class="org.scorpio.web.action.ManagerAction">
- <propertyname="managerService"ref="managerService"/>
- </bean>
- <beanname="/loginAction"class="org.scorpio.web.action.LoginAction">
- <propertyname="userService"ref="userService"/>
- <propertyname="managerService"ref="managerService"/>
- </bean>
- </beans>