`

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

    博客分类:
  • J2EE
阅读更多
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.OracleDriver</value>  
  28.   </property>  
  29.   <property name="url">  
  30.    <value>jdbc:oracle:thin:@192.168.1.8:1521:test</value>  
  31.   </property>  
  32.   <property name="username">  
  33.    <value>risk</value>  
  34.   </property>  
  35.   <property name="password">  
  36.    <value>123456</value>  
  37.   </property>  
  38.   <property name="maxActive">  
  39.    <value>20</value>  
  40.   </property>  
  41.   <property name="maxIdle">  
  42.    <value>5</value>  
  43.   </property>  
  44.   <property name="maxWait">  
  45.    <value>-1</value>  
  46.   </property>  
  47.   <property name="defaultAutoCommit">  
  48.    <value>true</value>  
  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/hbms</value>  
  66.    </list>  
  67.   </property>     
  68.   <property name="hibernateProperties">  
  69.    <props>  
  70.     <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>  
  71.     <prop key="hibernate.show_sql">false</prop>  
  72.     <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>  
  73.     <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>  
  74.     <prop key="hibernate.cache.use_query_cache">true</prop>  
  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_REQUIRED</prop>  
  93.     <prop key="add*">PROPAGATION_REQUIRED</prop>  
  94.     <prop key="set*">PROPAGATION_REQUIRED</prop>  
  95.     <prop key="update*">PROPAGATION_REQUIRED</prop>  
  96.     <prop key="delete*">PROPAGATION_REQUIRED</prop>  
  97.     <prop key="register">PROPAGATION_REQUIRED</prop>          
  98.     <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>  
  99.     <prop key="valid*">PROPAGATION_REQUIRED,readOnly</prop>  
  100.     <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>  
  101.    </props>  
  102.   </property>  
  103.  </bean>  
  104.   
  105.  <bean  
  106.   class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">  
  107.   <property name="beanNames">  
  108.    <value>*Service</value>  
  109.   </property>  
  110.   <property name="interceptorNames">  
  111.    <value>transactionInterceptor</value>  
  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>AllwapWeb</display-name>  
  152.  <distributable />  
  153.  <context-param>  
  154.   <param-name>contextConfigLocation</param-name>  
  155.   <param-value>/WEB-INF/applicationContext.xml /WEB-INF/dao.xml /WEB-INF/service.xml</param-value>  
  156.  </context-param>  
  157.  <listener>  
  158.   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  159.  </listener>  
  160.  <filter>  
  161.   <filter-name>struts</filter-name>  
  162.   <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>  
  163.   <init-param>  
  164.    <param-name>actionPackages</param-name>  
  165.    <param-value>cn.allwap.backend.action</param-value>  
  166.   </init-param>  
  167.  </filter>  
  168.  <servlet>  
  169.   <servlet-name>dwr</servlet-name>  
  170.   <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>  
  171.   <init-param>  
  172.    <param-name>debug</param-name>  
  173.    <param-value>true</param-value>  
  174.   </init-param>  
  175.  </servlet>    
  176.  <filter>  
  177.   <filter-name>openSession</filter-name>  
  178.   <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>  
  179.   <init-param>  
  180.    <param-name>singleSession</param-name>  
  181.    <param-value>false</param-value>  
  182.   </init-param>  
  183.  </filter>  
  184.  <filter>  
  185.   <filter-name>struts-cleanup</filter-name>  
  186.   <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>  
  187.  </filter>  
  188.  <filter>  
  189.   <filter-name>encodingFilter</filter-name>  
  190.   <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  191.   <init-param>  
  192.    <param-name>encoding</param-name>  
  193.    <param-value>UTF-8</param-value>  
  194.   </init-param>  
  195.  </filter>  
  196.  <filter-mapping>  
  197.   <filter-name>encodingFilter</filter-name>  
  198.   <url-pattern>/*</url-pattern>  
  199.  </filter-mapping>  
  200.  <filter-mapping>  
  201.   <filter-name>openSession</filter-name>  
  202.   <url-pattern>/*</url-pattern>  
  203.  </filter-mapping>  
  204.  <servlet-mapping>  
  205.   <servlet-name>dwr</servlet-name>  
  206.   <url-pattern>/dwr/*</url-pattern>  
  207.  </servlet-mapping>  
  208.  <filter-mapping>  
  209.   <filter-name>struts-cleanup</filter-name>  
  210.   <url-pattern>/*</url-pattern>  
  211.  </filter-mapping>  
  212.  <filter-mapping>  
  213.   <filter-name>struts</filter-name>  
  214.   <url-pattern>/*</url-pattern>  
  215.  </filter-mapping>  
  216.   
  217.  <welcome-file-list>  
  218.   <welcome-file>index.jsp</welcome-file>  
  219.   <welcome-file>default.jsp</welcome-file>  
  220.   <welcome-file>index.html</welcome-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. <!DOCTYPE struts PUBLIC   
  231.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"   
  232.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
  233.   
  234. <struts>  
  235.  <constant name="struts.enable.DynamicMethodInvocation" value="false" />  
  236.  <constant name="struts.devMode" value="false" />  
  237.  <constant name="struts.serve.static" value="true" />  
  238.  <constant name="struts.serve.static.browserCache" value="false" />    
  239.  <constant name="struts.action.extension" value="do" />  
  240.  <constant name="struts.configuration.xml.reload" value="true" />  
  241.  <constant name="struts.continuations.package" value="cn.nlinux.test.action" />  
  242.  <constant name="struts.multipart.saveDir" value="/resources/tmp" />  
  243.  <constant name="struts.multipart.maxSize" value="51200000000" />  
  244.  <constant name="struts.objectFactory" value="spring" />  
  245.  <constant name="struts.locale" value="zh_CN" />  
  246.  <constant name="struts.i18n.encoding" value="utf-8" />  
  247.  <constant name="struts.custom.i18n.resources" value="ApplicationResources" />  
  248.   
  249.     <include file="struts-test.xml" />  
  250.        
  251. </struts>  
  252.   
分享到:
评论
2 楼 hupeipei1986 2009-01-21  
ssss[color=yellow][/color][align=center]
xx-small][/si  ze][size=large]
1 楼 hupeipei1986 2009-01-21  
aaa[color=red][/color]aaaaa

相关推荐

Global site tag (gtag.js) - Google Analytics