SSH框架的搭建步骤(转载)

1.建立Web Project工程(File-New-Web Project-选择JavaEE 5.0) 2.在Web Project工程下添加Struts框架(选中工程-MyEclipse-Project Capabilities-Add Struts Capabilities..-选择Struts1.3) 3.在Web Project工程下添加Spring框架(选中工程-MyEclipse-Proje
  

 

 
1.建立Web Project工程(File->New->Web Project->选择JavaEE 5.0)

 

2.在Web Project工程下添加Struts框架(选中工程->MyEclipse->Project Capabilities->Add Struts Capabilities..->选择Struts1.3)

3.在Web Project工程下添加Spring框架(选中工程->MyEclipse->Project Capabilities->Add Spring Capabilities..->选中除(Hibernate 3.2 Annotations & Entity Manager-<MyEclipse-Libraries>、Hibernate 3.2 Advanced Support Libraries -<MyEclipse-Libraries>)、Toplink Essentials-<MyEclipse-Libraries>和OpenJPA -<MyEclipse-Libraries>的包)
自动生成ApplicationContext.xml
 
4.在Web Project工程下添加Hibernate 框架(选中工程->MyEclipse->Project Capabilities->Add Hibernate Capabilities.. ->清除(Hibernate 3.1 Core Libraries -<MyEclipse-Libraries>)选中包->在SessionFactory id中输入sessionFactory)
   
5.将数据表反转到工程:(选中表->右键选中Hibernate Reverse Engineering..
 
6.在Struts配置文件Struts-config.xml中加入plugin插件   
作用:<!-- web app 启动, 加载spring -->
<plug-in ClassName=”Org.Springframework.web.struts.ContextLoaderPlugIn” >
 <set-property property="contextConfigLocation"
  value="classpath:applicationContext.xml"/>
</plug-in>
 
7  在Struts-config.xml中:把action中的type设置为:
type="org.springframework.web.struts.DelegatingActionProxy"
 
8在生成好的单个实体DAO上生成接口,方法如下:
(右键 à refactor à Extract Interface……)
并且在其对应的action上生成接口对象,同时必须生成接口对象的get、set方法并且应用在excute方法中;
 
9在applicationContext.xml配置文件中:
   <bean name=" " class=" ">
              <property name="" ref=" ">
</property>
       </bean>
其中,bean中的name必须同struts-config.xml内的Action中的path保持一致!class是对应其action的路径。在property中的name是对应DAO所生成的接口在action中创建的对象名称。ref是对应DAO的名称。
 
10.在ApplicationContext.xml配置文件:
 
   <1>手动创建事务管理器;
<!-- 事务管理器 -->
   <bean id="txManager"
   class="org.springframework.orm.hibernate3.HibernateTransactionManager">
     <property name="sessionFactory" ref="sessionFactory"></property>
   </bean>
<2><!-- 事务策略通知 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
     <tx:attributes>
     <tx:method name="get*" propagation="SUPPORTS"
          read-only="true" />
   <tx:method name="find*" propagation="SUPPORTS"
          read-only="true" />
   <tx:method name="search*" propagation="SUPPORTS"
           read-only="true" />
     <tx:method name="*" propagation="REQUIRED" />
     </tx:attributes>
   </tx:advice>
<3>创建事务代理;
<!-- 事务代理 -->
       <aop:config>
   <aop:pointcut id="txDAO"
        expression="execution (* com.accp.entity.*.*(..))" />
   <aop:advisor pointcut-ref="txDAO" advice-ref="txAdvice" />
   </aop:config>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值