ssh框架的整合

struts1.x   hibernate  spring框架的整合

在applicationContext.xml文件中的配置如下

<beans>

    <!--DataSource-->

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

      <property name="driverClassName">

         <value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>

      </property>

      <property name="url">

          <value>jdbc:sqlserver://localhost:1433;DatabaseName=你的数据库名称;Select Method="cursor"</value>

      </property>

      <property name="username">

           <value>sa</value>

      </property>

       <property name="password" >

            <value>pwd<value>

        </property>

   </bean>

  

   <!--sessionFactory-->

   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

       <property name="dataSource">

              <ref local="dataSource"/>

       </property>

       <property name="mappingResources">

             <list>

                    <value>实体类的映射文件</value>

                    <value>--------------</value>

             </list>

       </property>

       <property name="hibernateProperties">

             <props>

                 <prop key="hibernate.dialect">

                       org.hibernate.dialect.SQLServerDialect

                 </prop>

                 <prop key="hibernate.show_sql">

                        true

                 </prop>

             </props>

       </property>

   </bean>

 <!-dao-->

  <bean id="userDao" class="com.daoImpl.userDaoImpl">

       <property name="sessionFactory" ref="sessionFactory">

  </bean>

<!--biz-->

   <bean id="userBiz" class="com.bizImpl.userBizImpl">

        <property name="userDao" ref="userDao">

        </property>

   </bean>

<!-- action -->

    <bean name="/user" class="com.action.UserAction">

        <property name="userBiz" ref="userBiz">

        </property>

    </bean>

</beans>

为了让spring生成action的实例,应该在struts-config.xml文件中配置插件,在struts-config.xm中的配置是

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">

     <set-property property="contextConfigLocation">

             <value>classpath:applicationContext.xml</value>

     </set-property>

</plug-in>

还有就是将相应的<action name="" type="">中的type改成 type="org.springframework.web.struts.DelegatingProxyAction>

struts1.x hibernate spring集成的第二种方式

1.在web.xml中配置监听器,就不用在struts-config.xml中配置 plugIn插件

<listener>

   <listener-class>

          org.springframework.web.context.ContextLoaderListener

   </listener-class>

</listener>

<Context>

   <param-name>contextConfigLocation</param-name>

   <param-value>

           classpath:applicationContext.xml

   </param-value>

</Context>

2.完成Action,由spring管理struts-config.xml,在struts-config.xml文件中配置controller

<Controller>

    <set-property property="processor" value="org.springframework.web.struts.DelegatingRequestProcessor">

</Controller>

这个配置要放在<message-resource>之前

3.在spring 中配置Action

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值