1:構建WEB項目java
2:構建數據庫mysql
3:加入依賴包spring
儘可能不要依賴IDE,經過本身手動加包完成sql
訪問數據庫須要的包:mysql的驅動包數據庫
Hibernate的包:hibernate3.jar 核心包express
依賴的必須包:antlr-2.7.6.jar 用於解析成HQL語句的包apache
commons-collections-3.1.jar apache提供的包,提供對集合框架的加強api
dom4j-1.6.1.jar 解析XML文件的包緩存
javassist-3.9.0.GA.jar 動態修改字節碼須要用到的包session
jta-1.1.jar 用於JTA事務的包
slf4j-api-1.5.8.jar 日誌接口包 ---》依賴必定的實現包
slf4j-log4j12-1.5.0.jar log4j.jar
另一種實現包:slf4j-simple-1.5.10.jar
可選的包:c3p0-0.9.1.jar 用於建立C3P0鏈接池的包
ehcache-1.2.3.jar :用於緩存實現的包
cglib-2.2.jar 動態修改字節碼的包
Spring的包:spring.jar 核心包
aopalliance.jar 使用Aop功能能夠用到的包
aspectjrt.jar
aspectjweaver.jar 使用ASPECTJ表達式須要用到的包
若是是使用DBCP鏈接池的話,須要兩個jar包
commons-dbcp.jar commons-pool.jar
若是須要用到commons增長包的話,能夠加入如下包
commons-beanutils.jar commons-lang.jar commons-logging.jar
Struts2的包:commons-fileupload-1.2.1.jar commons-io-1.3.2.jar
freemarker-2.3.13.jar :在Struts2 中默認使用的是FreeMarker模板引擎
ognl-2.6.11.jar : Struts2中使用OGNL表達式
struts2-core-2.1.6.jar 核心包
xwork-2.1.2.jar 核心包
struts2-spring-plugin-2.1.6.jar Struts2跟Spring整合須要的插件包
4:構建項目分包結構
5:放置配置文件
6:建立POJO和相對應的hbm.xml
7:修改空白的Hibernate.cfg..xml並建立表結構
8:建立DAO,SERVICE,ACTION
9:修改配置文件
ApplicationContext.xml
<!-- 利用Spring去管理SessionFactroy,須要告知Hibernate.cfg.xml的文件路徑 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> </bean> <!-- 配置GeneralDao,由於這個dao會被多個dao繼承使用 --> <bean id="generalDao" class="com.wanczy.common.GeneralDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 建立事務管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 定義Service層的事務傳播機制 --> <tx:advice id="serviceMethodAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="find*" read-only="true"/> <tx:method name="select*" read-only="true"/> <tx:method name="query*" read-only="true"/> <tx:method name="*"/> </tx:attributes> </tx:advice> <!-- 利用aop定義對那些包中的哪些類的哪些方法準備進行事務加強 --> <aop:config> <aop:pointcut id="serviceMethods" expression="execution (* com.wanczy.service.*.* (..))"/> <aop:advisor advice-ref="serviceMethodAdvice" pointcut-ref="serviceMethods"/> </aop:config> |
而且按照模塊的分佈進行applicationContext文件的配置
applicationContext_user.xml
<bean id="userDao" class="com.wanczy.dao.impl.UserDaoImpl" parent="generalDao"></bean> <bean id="userService" class="com.wanczy.service.impl.UserServiceImpl"> <property name="userDao" ref="userDao"></property> </bean> <bean id="userAction" class="com.wanczy.action.UserAction"> <property name="userService" ref="userService"></property> </bean> |