转自:http://hefeng1987-net-163-com.iteye.com/blog/941344spring
以前说了一下我所写的这个SSH2 OA项目所用的框架与工具.今天就来总结一下从搭建SSH2开发环境的过程到即将发布的机构管理这个小模块开发的实现思路. express
我所作这个项目的目的是来巩固复习Hibernate 和Spring这两个框架(Struts2一只在用).其基本思路和架构也都想好了,也打算利用晚上下班的时间来作出来.想法赶不上计划啊!这段时间有一些其余的事情,再者感受身体不是怎么好,情绪也受到影响,可能以后就抽出空去搞了.这里就把前几天所写的来公布于众.供你们学习.因为我也是刚刚参加工做,也没什么开发经验.代码写的有不足的地方请你们提出宝贵的意见与看法.
1.首先是搭建环境
虽然我是的是MyEclipse来开发,但我没有借助MyEclipse来帮助我,我所有是手动的方式来构建SSH2环境的.其三个框架所依赖的jar没有一个多余的,作到jar依赖的最小化.
整个项目架构是:
下面是application.xml中的(applicationcontext-common.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"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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">
-
- <!-- 配置sessionFactory -->
-
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="configLocation">
- <value>classpath:hibernate.cfg.xml</value>
- </property>
- </bean>
-
- <!-- 配置事务管理器 -->
- <!-- 配置事务管理器bean,使用HibernateTransactionManager事务管理器 -->
- <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <property name="sessionFactory">
- <ref bean="sessionFactory"/>
- </property>
- </bean>
-
- <!-- 配置事务的传播特性 -->
- <!-- 配置事务特性,配置add,delete,update开始的方法,事务传播特性为required -->
- <tx:advice id="txAdvice" transaction-manager="transactionManager">
- <tx:attributes>
- <tx:method name="add*" propagation="REQUIRED"/>
- <tx:method name="delete*" propagation="REQUIRED"/>
- <tx:method name="modify*" propagation="REQUIRED"/>
- <tx:method name="*" read-only="true"/>
- </tx:attributes>
- </tx:advice>
-
- <!-- 那些类的哪些方法参与事务 -->
- <!--
- <aop:config>
- <aop:advisor pointcut="execution(* com.oa.manager.*.*(..))" advice-ref="txAdvice"/>
- </aop:config>
- -->
- <!-- 配置那些类的方法进行事务管理,当前com.oa.manager包中的子包, 类中全部方法须要,还须要参考tx:advice的设置 -->
- <aop:config>
- <aop:pointcut id="allManageMethod" expression="execution(* com.oa.manager.*.*(..))" />
- <aop:advisor pointcut-ref="allManageMethod" advice-ref="txAdvice"/>
- </aop:config>
-
- <!-- 那些类的哪些方法参与事务 -->
- <!--
- <aop:config>
- <aop:advisor pointcut="execution(* com.oa.manager.*.*(..))" advice-ref="txAdvice"/>
- </aop:config>
- -->
- </beans>
2.机构管理的功能实现:
代码我打包上传了,效果实现过程能够看我所写的代码.(不知道怎么搞的,它不让我上传了!!!)