1.加入spring
1.加入spring jar
spring>required>all
2.配置web.xml文件
alt+/ 方向键上>contextloaderListener-ContextloaderListener
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
3.加入spring配置文件
新建>applicationContext.xml
2.加入Hibernate
1.加入jar
hibernate>required>all
2.在类路径下加入hibernate.cfg.xml文件,在其中配置Hibernate的基本属性
创建Hibernate.cfg.xml
<hibernate-configuration>
<property name="hibernate.dialect">org.hibernate.dialect.MySqlDialect</property>
... ...
</hibernate-configuration>
3,建立持久化类和其对应的.hbm.xml文件
3.和spring整合
1.加入c3p0和mysql驱动
2,在applicationContext.xml配置:
数据源,sessionFactory,声明式事务
3.添加data.properties 数据源配置
4.导入资源文件
<context:property-placeholder location="data.property"></context>
5.配置C3P0数据源
<bean id="dataSource" class="c3p0类">
6.配置sessionfactory
<bean id="sessionFactory" class="spring sessionfactory类"></>
7.配置spring声明式事务
1.配置hibernate事务管理器
<bean id="transactionManager" class="">
注入sessionfactory
2.配置事务属性
<tx:advice id="txAdvice" transaction-manager="trasactionManager"
<tx:attributes>
<tx:method name="get*" read-only="true">
3.配置事务切入点》再把事务属性和事务切入点关联起来
<aop:config>
<aop:pointcut expression="execution(路径)"
<aop:advisor advice-ref="txAvice" pointcut-ref="txPointcut"
8.启动project生成数据表
3.加入struts2
1.加入jar
Struts>apps>struts2-blank>web-inf>lib>all
注:javassist-xxx.jar重复,需要去掉版本低的哪一个
3.加入struts2配置文件》sturts.xml
4.在web.xml文件中配置Struts2 filter
5.整合spring
1.加入struts2的spting插件的jar
struts>lib>struts2-sping-plugin-xxx.jar
2.在spring的配置文件中正常配置action ,注意action的scope为prototype
3.在struts2的配置文件中配置action时,class属性指向action在IOC中的ID
4.完成功能
1.加入spring jar
spring>required>all
2.配置web.xml文件
alt+/ 方向键上>contextloaderListener-ContextloaderListener
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
3.加入spring配置文件
新建>applicationContext.xml
2.加入Hibernate
1.加入jar
hibernate>required>all
2.在类路径下加入hibernate.cfg.xml文件,在其中配置Hibernate的基本属性
创建Hibernate.cfg.xml
<hibernate-configuration>
<property name="hibernate.dialect">org.hibernate.dialect.MySqlDialect</property>
... ...
</hibernate-configuration>
3,建立持久化类和其对应的.hbm.xml文件
3.和spring整合
1.加入c3p0和mysql驱动
2,在applicationContext.xml配置:
数据源,sessionFactory,声明式事务
3.添加data.properties 数据源配置
4.导入资源文件
<context:property-placeholder location="data.property"></context>
5.配置C3P0数据源
<bean id="dataSource" class="c3p0类">
6.配置sessionfactory
<bean id="sessionFactory" class="spring sessionfactory类"></>
7.配置spring声明式事务
1.配置hibernate事务管理器
<bean id="transactionManager" class="">
注入sessionfactory
2.配置事务属性
<tx:advice id="txAdvice" transaction-manager="trasactionManager"
<tx:attributes>
<tx:method name="get*" read-only="true">
3.配置事务切入点》再把事务属性和事务切入点关联起来
<aop:config>
<aop:pointcut expression="execution(路径)"
<aop:advisor advice-ref="txAvice" pointcut-ref="txPointcut"
8.启动project生成数据表
3.加入struts2
1.加入jar
Struts>apps>struts2-blank>web-inf>lib>all
注:javassist-xxx.jar重复,需要去掉版本低的哪一个
3.加入struts2配置文件》sturts.xml
4.在web.xml文件中配置Struts2 filter
5.整合spring
1.加入struts2的spting插件的jar
struts>lib>struts2-sping-plugin-xxx.jar
2.在spring的配置文件中正常配置action ,注意action的scope为prototype
3.在struts2的配置文件中配置action时,class属性指向action在IOC中的ID
4.完成功能