http://blog.csdn.net/risk/archive/2007/06/28/1670129.aspx
xml 代码
- struts2.0+spring2.0 + hibernate 3.2 结合开发Web应用带来了很多改进,更多的是配置参数.以下结合开发项目说明如何使用struts2.0+spring2.0+hibernate3.2开放
- 数据库 oracle 9i/10g
- 包结构
- cn.nlinux.test.action 放置 struts 2.0 action
- cn.nilnux.test.bo 放置BO
- cn.nlinux.test.bo.hbms 放置hibernate3 的数据表 配置文件
- cn.nlinux.test.business PO接口
- cn.nlinux.test.business.service PO实现
- cn.nlinux.test.dao DAO接口
- cn.nlinux.test.dao.hibernate DAO实现
- 配置applicationContext.xml
- 此文件放置在/应用目录/WEB-INF/下
- 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: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">
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="driverClassName">
- <value>oracle.jdbc.driver.OracleDrivervalue>
- property>
- <property name="url">
- <value>jdbc:oracle:thin:@192.168.1.8:1521:testvalue>
- property>
- <property name="username">
- <value>riskvalue>
- property>
- <property name="password">
- <value>123456value>
- property>
- <property name="maxActive">
- <value>20value>
- property>
- <property name="maxIdle">
- <value>5value>
- property>
- <property name="maxWait">
- <value>-1value>
- property>
- <property name="defaultAutoCommit">
- <value>truevalue>
- property>
- bean>
- <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor" />
- <bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
- <property name="nativeJdbcExtractor">
- <ref bean="nativeJdbcExtractor" />
- property>
- bean>
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="dataSource">
- <ref local="dataSource" />
- property>
- <property name="mappingDirectoryLocations">
- <list>
- <value>classpath:/cn/nlinux/test/bo/hbmsvalue>
- list>
- property>
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialectprop>
- <prop key="hibernate.show_sql">falseprop>
- <prop key="hibernate.cglib.use_reflection_optimizer">trueprop>
- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProviderprop>
- <prop key="hibernate.cache.use_query_cache">trueprop>
- props>
- property>
- <property name="lobHandler" ref="oracleLobHandler" />
- bean>
- <bean id="transactionManager"
- class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <property name="sessionFactory">
- <ref bean="sessionFactory" />
- property>
- bean>
- <bean id="transactionInterceptor"
- class="org.springframework.transaction.interceptor.TransactionInterceptor">
- <property name="transactionManager" ref="transactionManager">property>
- <property name="transactionAttributes">
- <props>
- <prop key="save*">PROPAGATION_REQUIREDprop>
- <prop key="add*">PROPAGATION_REQUIREDprop>
- <prop key="set*">PROPAGATION_REQUIREDprop>
- <prop key="update*">PROPAGATION_REQUIREDprop>
- <prop key="delete*">PROPAGATION_REQUIREDprop>
- <prop key="register">PROPAGATION_REQUIREDprop>
- <prop key="find*">PROPAGATION_REQUIRED,readOnlyprop>
- <prop key="valid*">PROPAGATION_REQUIRED,readOnlyprop>
- <prop key="get*">PROPAGATION_REQUIRED,readOnlyprop>
- props>
- property>
- bean>
- <bean
- class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
- <property name="beanNames">
- <value>*Servicevalue>
- property>
- <property name="interceptorNames">
- <value>transactionInterceptorvalue>
- property>
- bean>
- <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
- <property name="transactionInterceptor" ref="transactionInterceptor">
- property>
- bean>
- beans>
- dao.xml 文件,用来配置 dao
- 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: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"
- default-autowire="byName">
- <bean id="employeeInfoDao" class="cn.nlinux.test.dao.hibernate.EmployeeInfoDao"/>
- <bean id="categoryInfoDao" class="cn.nlinux.test.dao.hibernate.CategoryInfoDao"/>
- beans>
- 配置委托文件 service.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: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"
- default-autowire="byName">
- <bean id="categoryService" class="cn.nlinux.test.business.service.CategoryService"/>
- <bean id="employeeService" class="cn.nlinux.test.business.service.EmployeeService"/>
- beans>
- web.xml 配置文件
- xml version="1.0" encoding="UTF-8"?>
- <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <display-name>AllwapWebdisplay-name>
- <distributable />
- <context-param>
- <param-name>contextConfigLocationparam-name>
- <param-value>/WEB-INF/applicationContext.xml /WEB-INF/dao.xml /WEB-INF/service.xmlparam-value>
- context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
- listener>
- <filter>
- <filter-name>strutsfilter-name>
- <filter-class>org.apache.struts2.dispatcher.FilterDispatcherfilter-class>
- <init-param>
- <param-name>actionPackagesparam-name>
- <param-value>cn.allwap.backend.actionparam-value>
- init-param>
- filter>
- <servlet>
- <servlet-name>dwrservlet-name>
- <servlet-class>uk.ltd.getahead.dwr.DWRServletservlet-class>
- <init-param>
- <param-name>debugparam-name>
- <param-value>trueparam-value>
- init-param>
- servlet>
- <filter>
- <filter-name>openSessionfilter-name>
- <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilterfilter-class>
- <init-param>
- <param-name>singleSessionparam-name>
- <param-value>falseparam-value>
- init-param>
- filter>
- <filter>
- <filter-name>struts-cleanupfilter-name>
- <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUpfilter-class>
- filter>
- <filter>
- <filter-name>encodingFilterfilter-name>
- <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
- <init-param>
- <param-name>encodingparam-name>
- <param-value>UTF-8param-value>
- init-param>
- filter>
- <filter-mapping>
- <filter-name>encodingFilterfilter-name>
- <url-pattern>/*url-pattern>
- filter-mapping>
- <filter-mapping>
- <filter-name>openSessionfilter-name>
- <url-pattern>/*url-pattern>
- filter-mapping>
- <servlet-mapping>
- <servlet-name>dwrservlet-name>
- <url-pattern>/dwr/*url-pattern>
- servlet-mapping>
- <filter-mapping>
- <filter-name>struts-cleanupfilter-name>
- <url-pattern>/*url-pattern>
- filter-mapping>
- <filter-mapping>
- <filter-name>strutsfilter-name>
- <url-pattern>/*url-pattern>
- filter-mapping>
- <welcome-file-list>
- <welcome-file>index.jspwelcome-file>
- <welcome-file>default.jspwelcome-file>
- <welcome-file>index.htmlwelcome-file>
- welcome-file-list>
- web-app>
- struts 2.0 配置文件
- struts.xml
- xml version="1.0" encoding="UTF-8" ?>
- "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
- "http://struts.apache.org/dtds/struts-2.0.dtd">
- <struts>
- <constant name="struts.enable.DynamicMethodInvocation" value="false" />
- <constant name="struts.devMode" value="false" />
- <constant name="struts.serve.static" value="true" />
- <constant name="struts.serve.static.browserCache" value="false" />
- <constant name="struts.action.extension" value="do" />
- <constant name="struts.configuration.xml.reload" value="true" />
- <constant name="struts.continuations.package" value="cn.nlinux.test.action" />
- <constant name="struts.multipart.saveDir" value="/resources/tmp" />
- <constant name="struts.multipart.maxSize" value="51200000000" />
- <constant name="struts.objectFactory" value="spring" />
- <constant name="struts.locale" value="zh_CN" />
- <constant name="struts.i18n.encoding" value="utf-8" />
- <constant name="struts.custom.i18n.resources" value="ApplicationResources" />
- <include file="struts-test.xml" />
- struts>
1 楼 hupeipei1986 2009-01-21
aaa[color=red][/color]aaaaa