<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麻豆丫| 亚洲高清中文字幕免费| 中文字幕亚洲综合小综合在线| 国产曰批免费视频播放免费s| 亚洲youjizz| 啦啦啦手机完整免费高清观看| 99999久久久久久亚洲| 免费看大美女大黄大色| 国产亚洲综合视频| 亚洲国产天堂久久久久久| 四虎影视在线看免费观看| 亚洲人成图片小说网站| 免费视频一区二区| 亚洲成a人片毛片在线| 嫩草影院在线免费观看| 污视频网站在线观看免费| 国产a v无码专区亚洲av| 国产午夜精品久久久久免费视| 99人中文字幕亚洲区 | a级毛片在线免费观看| 亚洲成年轻人电影网站www| 亚洲高清视频免费| 亚洲AV色欲色欲WWW| 三上悠亚亚洲一区高清| 91精品视频在线免费观看| 亚洲乱码一区av春药高潮| 国产免费卡一卡三卡乱码| 你懂的网址免费国产| 亚洲免费视频播放| 免费一级毛片在线播放| 日韩免费在线观看视频| 亚洲中文无码亚洲人成影院| 亚洲精品黄色视频在线观看免费资源| 久久99热精品免费观看牛牛| 亚洲午夜福利在线视频| 中文字幕在线亚洲精品| 成人免费午夜在线观看| 中文无码日韩欧免费视频| 亚洲男人天堂2018av|