SSH框架搭建

                               SSH框架搭建

A)首先集成spring2.5,勾选spirng2.5 Persistence JDBC ,勾选Spring2.5 J2EE Libraries ,勾选Spring2.5 Web Libraries  然后JAR Library Installaction选第二个,意思是jar包给lib管理  然后按 Next 。再按Finish。


B)集成hibernate3.1 然后AR Library Installaction选第二个,意思是jar包给lib管理 ,

按Next。选择Spring configuration fine(applictionContext.xml)意思配置都交给Spring来管理。按Next。

选择Existing Spring configuration file. 按Next.配置链接数据库,(这里配置数据库建议创建一个逆向工程

,然后再配置数据库这块直接选就可以了) 按Next.  把勾选的取消掉,应为我们可以从spring中获取。 按Finish.


C)集成Struts2.1 .URL pattern:选择/* 按Finish.

D)删除这两个jar包分别: antlr-2.7.2 asm-2.2.3 否则会有冲突。 然后导入综合的jar包:struts2-spring-plugin-2.1.8.1

 然后把这个Struts 2 Core Libraries 这个struts2自带的一个Remove掉,应为综合的jar包有带struts2需要的jar:


 E)配置事务管理:单独创建一个applicationContext.tran.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.0.xsd
     http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
      
      <!-- 配置事物管理 -->
    <bean id="transactionManager"  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>        
    </bean>
    
    <!-- 配置实物传播特性 -->
    <tx:advice id="txadvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>
    
    
    <aop:config>          指定对那些方法做事务处理。 //表达式:返回值  包名.类名.方法名(参数)
        <aop:pointcut id="allService" expression="execution(* com.kit.service.*.*(..))"/>
        <aop:advisor pointcut-ref="allService" advice-ref="txadvice"/>
    </aop:config>
 
      
      </beans>
   
  F)applictionContext.user.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:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    <!-- 利用依赖倒置原理 把组件之间的关系给控制起来。 -->
    <bean id="studentdao" class="dao.StudentDAOimpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
     </bean>

    <bean id="studentService" class="service.StudentServiceImpl">
        <property name="studendao" ref="studentdao"></property>
    </bean>
                                                            <!--
                                                                                                                                 设置多例 表单 scope="prototype"
                                                             -->
    <bean id="studentAction" class="web.action.StudentAction" scope="prototype">
        <property name="studentService" ref="studentService"></property>
    </bean>
    
  G)struts.xml配置文件如下:  

   <?xml version="1.0" encoding="UTF-8" ?>
         <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"         "http://struts.apache.org/dtds/struts-2.1.dtd">
          <struts>

    <package name="struts2" namespace="/" extends="struts-default">
                                <!--class 改成了spring的 id  -->
        <action name="student" class="studentAction">
            <result>/index.jsp</result>
        </action>
       </package></struts>    
 


 
 
  F)web.xml配置如下:

   ?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
    
    <filter>
        <filter-name>session</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>session</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
<!-- 给配置文件定位 -->
<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>
    
    
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <filter>
      <filter-name>struts2</filter-name>
      <filter-class>
          org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      </filter-class>
  </filter>
  <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping></web-app>

  配置差不多了只要配置代码组件就可以了~~~


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值