spring 2.0 + hibernate3.2 + struts 2.0 开放配置

阅读更多
http://blog.csdn.net/risk/archive/2007/06/28/1670129.aspx
xml 代码
  1. struts2.0+spring2.0 + hibernate 3.2 结合开发Web应用带来了很多改进,更多的是配置参数.以下结合开发项目说明如何使用struts2.0+spring2.0+hibernate3.2开放   
  2.   
  3.   
  4. 数据库 oracle 9i/10g   
  5.   
  6. 包结构   
  7. cn.nlinux.test.action 放置 struts 2.0 action    
  8. cn.nilnux.test.bo 放置BO   
  9. cn.nlinux.test.bo.hbms 放置hibernate3 的数据表 配置文件   
  10. cn.nlinux.test.business PO接口   
  11. cn.nlinux.test.business.service PO实现   
  12. cn.nlinux.test.dao DAO接口   
  13. cn.nlinux.test.dao.hibernate DAO实现   
  14.   
  15.     
  16.   
  17. 配置applicationContext.xml   
  18. 此文件放置在/应用目录/WEB-INF/下   
  19. xml version="1.0" encoding="UTF-8"?>  
  20. <beans xmlns="http://www.springframework.org/schema/beans"  
  21.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  22.  xmlns:lang="http://www.springframework.org/schema/lang"  
  23.  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">  
  24.   
  25.  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">  
  26.   <property name="driverClassName">  
  27.    <value>oracle.jdbc.driver.OracleDrivervalue>  
  28.   property>  
  29.   <property name="url">  
  30.    <value>jdbc:oracle:thin:@192.168.1.8:1521:testvalue>  
  31.   property>  
  32.   <property name="username">  
  33.    <value>riskvalue>  
  34.   property>  
  35.   <property name="password">  
  36.    <value>123456value>  
  37.   property>  
  38.   <property name="maxActive">  
  39.    <value>20value>  
  40.   property>  
  41.   <property name="maxIdle">  
  42.    <value>5value>  
  43.   property>  
  44.   <property name="maxWait">  
  45.    <value>-1value>  
  46.   property>  
  47.   <property name="defaultAutoCommit">  
  48.    <value>truevalue>  
  49.   property>  
  50.  bean>  
  51.   
  52.  <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor" />    
  53.  <bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">    
  54.   <property name="nativeJdbcExtractor">    
  55.    <ref bean="nativeJdbcExtractor" />    
  56.   property>    
  57.  bean>    
  58.   
  59.  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  60.   <property name="dataSource">  
  61.    <ref local="dataSource" />  
  62.   property>     
  63.   <property name="mappingDirectoryLocations">  
  64.    <list>  
  65.     <value>classpath:/cn/nlinux/test/bo/hbmsvalue>  
  66.    list>  
  67.   property>     
  68.   <property name="hibernateProperties">  
  69.    <props>  
  70.     <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialectprop>  
  71.     <prop key="hibernate.show_sql">falseprop>  
  72.     <prop key="hibernate.cglib.use_reflection_optimizer">trueprop>  
  73.     <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProviderprop>  
  74.     <prop key="hibernate.cache.use_query_cache">trueprop>  
  75.    props>  
  76.   property>  
  77.   <property name="lobHandler" ref="oracleLobHandler" />  
  78.  bean>  
  79.     
  80.  <bean id="transactionManager"  
  81.   class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  82.   <property name="sessionFactory">  
  83.    <ref bean="sessionFactory" />  
  84.   property>  
  85.  bean>  
  86.   
  87.  <bean id="transactionInterceptor"  
  88.   class="org.springframework.transaction.interceptor.TransactionInterceptor">  
  89.   <property name="transactionManager" ref="transactionManager">property>  
  90.   <property name="transactionAttributes">  
  91.    <props>  
  92.     <prop key="save*">PROPAGATION_REQUIREDprop>  
  93.     <prop key="add*">PROPAGATION_REQUIREDprop>  
  94.     <prop key="set*">PROPAGATION_REQUIREDprop>  
  95.     <prop key="update*">PROPAGATION_REQUIREDprop>  
  96.     <prop key="delete*">PROPAGATION_REQUIREDprop>  
  97.     <prop key="register">PROPAGATION_REQUIREDprop>          
  98.     <prop key="find*">PROPAGATION_REQUIRED,readOnlyprop>  
  99.     <prop key="valid*">PROPAGATION_REQUIRED,readOnlyprop>  
  100.     <prop key="get*">PROPAGATION_REQUIRED,readOnlyprop>  
  101.    props>  
  102.   property>  
  103.  bean>  
  104.   
  105.  <bean  
  106.   class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">  
  107.   <property name="beanNames">  
  108.    <value>*Servicevalue>  
  109.   property>  
  110.   <property name="interceptorNames">  
  111.    <value>transactionInterceptorvalue>  
  112.   property>  
  113.  bean>  
  114.   
  115.  <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">  
  116.   <property name="transactionInterceptor" ref="transactionInterceptor">  
  117.   property>  
  118.  bean>  
  119.   
  120. beans>  
  121.   
  122. dao.xml 文件,用来配置 dao   
  123. xml version="1.0" encoding="UTF-8"?>  
  124. <beans xmlns="http://www.springframework.org/schema/beans"  
  125.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  126.  xmlns:lang="http://www.springframework.org/schema/lang"  
  127.  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"  
  128.  default-autowire="byName">    
  129.  <bean id="employeeInfoDao" class="cn.nlinux.test.dao.hibernate.EmployeeInfoDao"/>  
  130.  <bean id="categoryInfoDao" class="cn.nlinux.test.dao.hibernate.CategoryInfoDao"/>    
  131.     
  132. beans>  
  133. 配置委托文件 service.xml   
  134. xml version="1.0" encoding="UTF-8"?>  
  135. <beans xmlns="http://www.springframework.org/schema/beans"  
  136.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  137.  xmlns:lang="http://www.springframework.org/schema/lang"  
  138.  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"  
  139.  default-autowire="byName">  
  140.  <bean id="categoryService" class="cn.nlinux.test.business.service.CategoryService"/>  
  141.  <bean id="employeeService" class="cn.nlinux.test.business.service.EmployeeService"/>     
  142. beans>    
  143.   
  144.   
  145. web.xml 配置文件   
  146.   
  147. xml version="1.0" encoding="UTF-8"?>  
  148. <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"  
  149.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  150.  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  151.  <display-name>AllwapWebdisplay-name>  
  152.  <distributable />  
  153.  <context-param>  
  154.   <param-name>contextConfigLocationparam-name>  
  155.   <param-value>/WEB-INF/applicationContext.xml /WEB-INF/dao.xml /WEB-INF/service.xmlparam-value>  
  156.  context-param>  
  157.  <listener>  
  158.   <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>  
  159.  listener>  
  160.  <filter>  
  161.   <filter-name>strutsfilter-name>  
  162.   <filter-class>org.apache.struts2.dispatcher.FilterDispatcherfilter-class>  
  163.   <init-param>  
  164.    <param-name>actionPackagesparam-name>  
  165.    <param-value>cn.allwap.backend.actionparam-value>  
  166.   init-param>  
  167.  filter>  
  168.  <servlet>  
  169.   <servlet-name>dwrservlet-name>  
  170.   <servlet-class>uk.ltd.getahead.dwr.DWRServletservlet-class>  
  171.   <init-param>  
  172.    <param-name>debugparam-name>  
  173.    <param-value>trueparam-value>  
  174.   init-param>  
  175.  servlet>    
  176.  <filter>  
  177.   <filter-name>openSessionfilter-name>  
  178.   <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilterfilter-class>  
  179.   <init-param>  
  180.    <param-name>singleSessionparam-name>  
  181.    <param-value>falseparam-value>  
  182.   init-param>  
  183.  filter>  
  184.  <filter>  
  185.   <filter-name>struts-cleanupfilter-name>  
  186.   <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUpfilter-class>  
  187.  filter>  
  188.  <filter>  
  189.   <filter-name>encodingFilterfilter-name>  
  190.   <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>  
  191.   <init-param>  
  192.    <param-name>encodingparam-name>  
  193.    <param-value>UTF-8param-value>  
  194.   init-param>  
  195.  filter>  
  196.  <filter-mapping>  
  197.   <filter-name>encodingFilterfilter-name>  
  198.   <url-pattern>/*url-pattern>  
  199.  filter-mapping>  
  200.  <filter-mapping>  
  201.   <filter-name>openSessionfilter-name>  
  202.   <url-pattern>/*url-pattern>  
  203.  filter-mapping>  
  204.  <servlet-mapping>  
  205.   <servlet-name>dwrservlet-name>  
  206.   <url-pattern>/dwr/*url-pattern>  
  207.  servlet-mapping>  
  208.  <filter-mapping>  
  209.   <filter-name>struts-cleanupfilter-name>  
  210.   <url-pattern>/*url-pattern>  
  211.  filter-mapping>  
  212.  <filter-mapping>  
  213.   <filter-name>strutsfilter-name>  
  214.   <url-pattern>/*url-pattern>  
  215.  filter-mapping>  
  216.   
  217.  <welcome-file-list>  
  218.   <welcome-file>index.jspwelcome-file>  
  219.   <welcome-file>default.jspwelcome-file>  
  220.   <welcome-file>index.htmlwelcome-file>  
  221.  welcome-file-list>  
  222. web-app>  
  223.   
  224. struts 2.0 配置文件   
  225.   
  226. struts.xml   
  227.   
  228. xml version="1.0" encoding="UTF-8" ?>  
  229.   
  230.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"   
  231.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
  232.   
  233. <struts>  
  234.  <constant name="struts.enable.DynamicMethodInvocation" value="false" />  
  235.  <constant name="struts.devMode" value="false" />  
  236.  <constant name="struts.serve.static" value="true" />  
  237.  <constant name="struts.serve.static.browserCache" value="false" />    
  238.  <constant name="struts.action.extension" value="do" />  
  239.  <constant name="struts.configuration.xml.reload" value="true" />  
  240.  <constant name="struts.continuations.package" value="cn.nlinux.test.action" />  
  241.  <constant name="struts.multipart.saveDir" value="/resources/tmp" />  
  242.  <constant name="struts.multipart.maxSize" value="51200000000" />  
  243.  <constant name="struts.objectFactory" value="spring" />  
  244.  <constant name="struts.locale" value="zh_CN" />  
  245.  <constant name="struts.i18n.encoding" value="utf-8" />  
  246.  <constant name="struts.custom.i18n.resources" value="ApplicationResources" />  
  247.   
  248.     <include file="struts-test.xml" />  
  249.        
  250. struts>  
  251.   
1 楼 hupeipei1986 2009-01-21  
aaa[color=red][/color]aaaaa

你可能感兴趣的:(Struts,Spring,Bean,Hibernate,DWR)