<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    vjame

    優化代碼是無止境的
    隨筆 - 65, 文章 - 9, 評論 - 26, 引用 - 0
    數據加載中……

    手工搭建spring2.0_struts1.2.9_hibernate3.2.5集成環境

    1、首先在MyEclipse創建web工程,project name 為spring_struts_hibernate


    2、先加入struts的支持。拷貝struts的jar到工程里的WEB-INF下的lib中


    3、然后再拷貝jstl類庫,核心和標準庫


    4、修改web.xml文件來配置ActionServlet
    <servlet>
            
    <servlet-name>action</servlet-name>
            
    <servlet-class>
                org.apache.struts.action.ActionServlet
            
    </servlet-class>
            
    <init-param>
                
    <param-name>config</param-name>
                
    <param-value>/WEB-INF/struts-config.xml</param-value>
            
    </init-param>
            
    <init-param>
                
    <param-name>debug</param-name>
                
    <param-value>2</param-value>
            
    </init-param>
            
    <init-param>
                
    <param-name>detail</param-name>
                
    <param-value>2</param-value>
            
    </init-param>
            
    <load-on-startup>2</load-on-startup>
        
    </servlet>


        
    <!-- Standard Action Servlet Mapping -->
        
    <servlet-mapping>
            
    <servlet-name>action</servlet-name>
            
    <url-pattern>*.do</url-pattern>
        
    </servlet-mapping>

    5、提供struts-config.xml文件


    6、提供國際化資源文件

    # -- standard errors --
    errors.header=<UL>
    errors.prefix=<LI>
    errors.suffix=</LI>
    errors.footer=</UL>
    # -- validator --
    errors.invalid={0} is invalid.
    errors.maxlength={0} can not be greater than {1} characters.
    errors.minlength={0} can not be less than {1} characters.
    errors.range={0} is not in the range {1} through {2}.
    errors.required={0} is required.
    errors.byte={0} must be an byte.
    errors.date={0} is not a date.
    errors.double={0} must be an double.
    errors.float={0} must be an float.
    errors.integer={0} must be an integer.
    errors.long={0} must be an long.
    errors.short={0} must be an short.
    errors.creditcard={0} is not a valid credit card number.
    errors.email={0} is an invalid e-mail address.
    # -- other --
    errors.cancel=Operation cancelled.
    errors.detail={0}
    errors.general=The process did not complete. Details should follow.
    errors.token=Request could not be completed. Operation is not in sequence.
    # -- welcome --
    welcome.title=Struts Blank Application
    welcome.heading=Welcome!
    welcome.message=To get started on your own application, copy the struts-blank.war to a new WAR file using the name for your application. Place it in your container's "webapp" folder (or equivalent), and let your container auto-deploy the application. Edit the skeleton configuration files as needed, restart your container, and you are on your way! (You can find the application.properties file with this message in the /WEB-INF/src/java/resources folder.)

    7、加入spring支持。拷貝spring類庫,首先加入spring核心jar


    然后再加入\spring-framework-2.0-with-dependencies\spring-framework-2.0\lib下的
    日志記錄 log4j-1.2.14.jar
    aop支持 aspectjrt.jar  aspectjweaver.jar
    commons-logging.jar

    8、提供spring配置文件

    applicationContext-action.xml  配置struts中的action
    applicationContext-bean.xml 配置業務對象,service層

    applicationContext-common.xml 配置sessionFactory和事務
    <?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/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
    >
        
    <!-- 配置sessionFactory -->
        
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            
    <property name="configLocation">
                
    <value>classpath:hibernate.cfg.xml</value>
            
    </property>    
        
    </bean>           
        
        
    <!-- 配置事務管理器 -->
        
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            
    <property name="sessionFactory">
                
    <ref bean="sessionFactory"/>
            
    </property>    
        
    </bean>
        
        
    <!-- 配置事務的傳播特性 -->
        
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
            
    <tx:attributes>
                
    <tx:method name="add*" propagation="REQUIRED"/>
                
    <tx:method name="del*" propagation="REQUIRED"/>
                
    <tx:method name="modify*" propagation="REQUIRED"/>
                
    <tx:method name="*" read-only="true"/>
            
    </tx:attributes>
        
    </tx:advice>
        
        
    <!-- 那些類的哪些方法參與事務   所有類所有方法-->
        
    <aop:config>
            
    <aop:pointcut id="allManagerMethod" expression="execution(* com.strongit.usermgr.manager.*.*(..))"/>
            
    <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
        
    </aop:config>
        
        
    </beans>


    spring與struts集成,在struts-config文件中配置action的type屬性要設置為spring的代理
    eg.
    <action path="/login"
                    type
    ="org.springframework.web.struts.DelegatingActionProxy"
                    name
    ="loginForm"
                    scope
    ="request"    
            
    >
                
    <forward name="success" path="/success.jsp"/>
            
    </action>

    applicationContext-action.xml文件中配置
    <bean name="/login" class="com.bjsxt.usermgr.actions.LoginAction" scope="prototype">
            
    <property name="userManager" ref="userManager"/>
        
    </bean>


    9、修改web.xml配置spring
    <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>

    10、加入hibernate的支持。把這些jar包全部拷貝帶WEB-INF下lib中


    11、配置hibernate的配置文件hibernate.cfg.xml
    <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
    >

    <hibernate-configuration>
        
    <session-factory>
            
    <property name="hibernate.connection.url">jdbc:mysql://localhost/spring_struts_hibernate</property>
            
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
            
    <property name="hibernate.connection.username">root</property>
            
    <property name="hibernate.connection.password">root</property>
            
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
            
    <property name="hibernate.show_sql">true</property>
            
    <property name="hibernate.hbm2ddl.auto">update</property>
        
    </session-factory>
    </hibernate-configuration>
    該配置文件在applicationContext-common.xml配置中有引用到
        <!-- 配置sessionFactory -->
        
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            
    <property name="configLocation">
                
    <value>classpath:hibernate.cfg.xml</value>
            
    </property>    
        
    </bean>   

    12、至此,ssh集成基本完成,還有一些lib重復的我們可以刪除,以保留新版本為準。
     所有涉及到的jar包版本如下
    hibernate-3.2.5.ga.rar
    spring-framework-2.0-with-dependencies.zip
    struts-1.2.9-bin.zip
    jakarta-taglibs-standard-1.1.2.zip

    posted on 2009-08-09 17:04 lanjh 閱讀(978) 評論(2)  編輯  收藏 所屬分類: Java Web

    評論

    # re: 手工搭建spring2.0_struts1.2.9_hibernate3.2.5集成環境  回復  更多評論   

    在Struts-config.xml中不需要配置<controller>或者<plug-in>元素么?
    2012-03-16 10:00 | GavinMiao

    # re: 手工搭建spring2.0_struts1.2.9_hibernate3.2.5集成環境  回復  更多評論   

    @GavinMiao
    配置文件中的action屬性已經配置了以下的東東type="org.springframework.web.struts.DelegatingActionProxy"
    2012-03-16 14:36 | lanjh
    主站蜘蛛池模板: 亚洲最大av无码网址| 色影音免费色资源| 亚洲av片在线观看| 美女的胸又黄又www网站免费| 丁香六月婷婷精品免费观看 | 亚洲视频一区二区三区| 亚洲白嫩在线观看| 亚洲av永久无码天堂网| 成人a视频片在线观看免费| 亚洲AV成人影视在线观看| 亚洲精品GV天堂无码男同| 久久久久国色AV免费观看| 久久成人免费电影| 国产成人免费高清激情视频| 亚洲精品老司机在线观看| 亚洲午夜电影在线观看高清 | 美女被cao网站免费看在线看| 日韩av无码成人无码免费| 亚洲 日韩 色 图网站| 免费观看男人免费桶女人视频| 亚洲av无码不卡| 黄色一级视频免费观看| 国产精品亚洲精品日韩已满| 亚洲AV无码XXX麻豆艾秋| 亚洲成AⅤ人影院在线观看| 亚洲综合av一区二区三区不卡 | 国产亚洲午夜精品| 免费三级毛片电影片| 亚洲精品视频在线| av片在线观看永久免费| 成人免费视频试看120秒| 亚洲综合久久久久久中文字幕| www.黄色免费网站| 亚洲精品美女久久久久9999| 成人片黄网站A毛片免费| 一区二区在线视频免费观看| 亚洲精品视频在线观看免费| 永久免费看bbb| 麻豆精品不卡国产免费看| 亚洲精品理论电影在线观看| 亚洲中文字幕无码一久久区|