隨筆-8  評論-8  文章-10  trackbacks-0
          一、整合jar包
                  首先下載3個框架
                  struts2.0           下載地址    http://apache.freelamp.com/struts/binaries/struts-2.0.14-all.zip
                  spring2.5          下載地址    http://s3.amazonaws.com/dist.springframework.org/release/SPR/spring-framework-2.5.6.SEC01-with-dependencies.zip     
                  hibernate3.3     下載地址    http://downloads.sourceforge.net/project/hibernate/hibernate3/3.3.2.GA/hibernate-distribution-3.3.2.GA-dist.zip

                  struts/lib下 找出以下5個jar文件 它們是使用struts2必須的jar文件
                      commons-logging-1.0.4.jar
                      freemarker-2.3.8.jar
                      ognl-2.6.11.jar
                      struts2-core-2.0.11.1.jar
                      xwork-2.0.4.jar
                      再找出  struts2-spring-plugin-2.0.14.jar   它是struts2與spring整合必須的jar文件

                  spring/dist下 
                      spring.jar
                  spring/lib/aspectj下  在spring中使用aspectj 必須的jar包
                      aspectjrt.jar
                      aspectjweaver.jar
                  spring/lib/log4j
                      log4j-1.2.15.jar

                  hibernate/hibernate3.jar
                  hibernate/lib/required 下 所有jar文件 它們是使用hibernate必須的jar文件
                  注意其中有slf4j-api-1.5.8.jar 文件 它只是一個規(guī)范
                  我們需要下載它對log4j實現(xiàn)的jar文件
                  下載地址 http://www.slf4j.org/dist/slf4j-1.5.2.zip
                  找出其中有一個slf4j-log4j12-1.5.2.jar 

                  以上一共18個jar文件
                  
            二、修改配置文件
                  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"
          >
              
          <context-param>
                  
          <param-name>contextConfigLocation</param-name>
                  
          <param-value>classpath*:applicationContext-*.xml</param-value>
              
          </context-param>

              
          <filter>
                  
          <filter-name>struts2</filter-name>
                  
          <filter-class>
                      org.apache.struts2.dispatcher.FilterDispatcher
                  
          </filter-class>
              
          </filter>
              
          <filter-mapping>
                  
          <filter-name>struts2</filter-name>
                  
          <url-pattern>/*</url-pattern>
              
          </filter-mapping>
              
              
          <filter>
                  
          <filter-name>hibernateFilter</filter-name>
                  
          <filter-class>
                      org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
                  
          </filter-class>
              
          </filter>
              
          <filter-mapping>
                  
          <filter-name>hibernateFilter</filter-name>
                  
          <url-pattern>*.action</url-pattern>
              
          </filter-mapping>
              
              
              
          <filter>   
              
          <filter-name>Spring character encoding filter</filter-name>   
              
          <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>   
                  
          <init-param>   
                      
          <param-name>encoding</param-name>   
                      
          <param-value>GBK</param-value>   
                  
          </init-param>   
              
          </filter>   
              
          <filter-mapping>   
                  
          <filter-name>Spring character encoding filter</filter-name>   
                  
          <url-pattern>/*</url-pattern>   
              
          </filter-mapping>
              
              
          <listener>
                  
          <listener-class>
                      org.springframework.web.context.ContextLoaderListener
                  
          </listener-class>
              
          </listener>

              
          <welcome-file-list>
                  
          <welcome-file>index.jsp</welcome-file>
              
          </welcome-file-list>
          </web-app>

          hibernate.cfg.xml
          <?xml version="1.0"?>
          <!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="format_sql">false</property>
                  
          <property name="show_sql">true</property>
                  
          <property name="connection.driver_class">
                      org.gjt.mm.mysql.Driver
                  
          </property>
                  
          <property name="connection.url">
                      jdbc:mysql://localhost:3306/s2sh
                  
          </property>
                  
          <property name="connection.username">root</property>
                  
          <property name="connection.password">password</property>
                  
          <property name="dialect">
                      org.hibernate.dialect.MySQLDialect
                  
          </property>
                  
          <property name="hbm2ddl.auto">none</property>
                  
          <mapping resource="com/illu/pojo/User.hbm.xml" />
              
          </session-factory>
          </hibernate-configuration>

          applicationContext.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"
              xmlns:lang
          ="http://www.springframework.org/schema/lang"
              xsi:schemaLocation
          ="
                  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                  http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd 
                  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
                  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"
          >
              
              
          <bean id="sessionFactory"
                  class
          ="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                  
          <property name="configLocation">
                      
          <value>classpath:hibernate.cfg.xml</value>
                  
          </property>
              
          </bean>
              
              
          <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
                  
          <property name="sessionFactory">
                      
          <ref bean="sessionFactory"/>
                  
          </property>
              
          </bean>
              
              
          <!-- 配置事務(wù)管理器 -->

              
          <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="delete*" propagation="REQUIRED" />
                      
          <tx:method name="modify*" propagation="REQUIRED" />
                      
          <tx:method name="*" read-only="true" />
                  
          </tx:attributes>
              
          </tx:advice>

              
          <!-- 哪些類的哪些方法參與事物, (* com.evan.crm.service.*.*(..))中幾個通配符的含義:
                  第一個 * —— 通配 任意返回值類型
                  第二個 * —— 通配 包com.evan.crm.service下的任意class
                  第三個 * —— 通配 包com.evan.crm.service下的任意class的任意方法
                  第四個 .. —— 通配 方法可以有0個或多個參數(shù)
                  綜上:包com.evan.crm.service下的任意class的具有任意返回值類型、任意數(shù)目參數(shù)和任意名稱的方法
          -->
              
          <aop:config>
                  
          <aop:pointcut id="allManagerMethod"
                      expression
          ="execution(* com.struts2.service.*.*(..))" />
                  
          <aop:advisor pointcut-ref="allManagerMethod"
                      advice-ref
          ="txAdvice" />
              
          </aop:config>
          </beans>





          每天進步一點點

          posted on 2009-07-27 14:49 應(yīng)越 閱讀(1297) 評論(0)  編輯  收藏 所屬分類: struts2.0

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 长治县| 蕉岭县| 平凉市| 乌拉特中旗| 大庆市| 察雅县| 登封市| 石楼县| 仪陇县| 凤城市| 远安县| 九寨沟县| 闸北区| 怀宁县| 寿光市| 辉县市| 深圳市| 中江县| 夹江县| 汶上县| 漳州市| 朝阳县| 无锡市| 香河县| 紫云| 祥云县| 宜春市| 连云港市| 苏尼特右旗| 长顺县| 社旗县| 禄劝| 鱼台县| 彭州市| 桐庐县| 大埔县| 榆中县| 富裕县| 津市市| 天等县| 黎平县|