web.xml之Spring配置(基于Spring+Struts+Ibatis)

编程技术  /  houtizong 发布于 3年前   68

指定Spring配置文件位置

<context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/spring-dao-bean.xml,/WEB-INF/spring-resources.xml,/WEB-INF/spring-service-bean.xml</param-value></context-param>

定义Spring监听器加载Spring

<listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>

配置Struts

<servlet><servlet-name>action</servlet-name><servlet-class>com.weboa.util.web.EbusinessActionServlet</servlet-class><init-param><param-name>config</param-name><param-value>/WEB-INF/struts-config.xml</param-value></init-param><!-- module configurations --><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><servlet-mapping><servlet-name>action</servlet-name><url-pattern>*.htm</url-pattern></servlet-mapping>

定义:spring-dao-bean.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:jee="http://www.springframework.org/schema/jee" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd" ><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><bean id="sqlMapClient"class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><property name="configLocation"><value>classpath:/com/ibatis/sql-map-config.xml</value></property><property name="dataSource" ref="dataSource" /></bean></beans>

定义:spring-resources.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:context="http://www.springframework.org/schema/context"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.5.xsd       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">    <!-- 数据库连接 -->    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">    <property name="location">       <value>/WEB-INF/classes/jdbc.properties</value>    </property></bean>    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">        <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/>        <property name="username" value="${jdbc.user}"/>        <property name="password" value="${jdbc.password}"/>        <property name="maxActive" value="${jdbc.maxActive}"/>        <property name="maxIdle" value="${jdbc.maxIdle}"/>        <property name="maxWait" value="${jdbc.maxWait}"/>        <property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}"/>        <property name="removeAbandoned" value="${jdbc.removeAbandoned}"/>        <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>    </bean></beans>

定义Spring-service-bean.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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"><bean id="txProxyTemplate" abstract="true"class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"><property name="transactionManager" ref="transactionManager" /><property name="transactionAttributes"><props><prop key="save*">PROPAGATION_REQUIRED,-Exception</prop><prop key="remove*">PROPAGATION_REQUIRED,-Exception</prop><prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop><prop key="update*">PROPAGATION_REQUIRED,-Exception</prop><prop key="updateFolder">PROPAGATION_REQUIRED, timeout_30</prop><prop key="*">PROPAGATION_REQUIRED,readOnly</prop></props></property></bean><bean id="userCache"class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache"><property name="cache"><beanclass="org.springframework.cache.ehcache.EhCacheFactoryBean"><property name="cacheManager"><beanclass="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" /></property><property name="cacheName" value="userCache" /></bean></property></bean><!-- *********************2009.4.24添加,得到acegi中保存的用户信息******************* --><bean id="sessionRegistry" class="org.acegisecurity.concurrent.SessionRegistryImpl"/><!-- *****************************个人事务************************** --><!-- 日程安排 --><bean id="arrangementService" parent="txProxyTemplate"><property name="target"><beanclass="com.weboa.personalService.service.impl.ArrangementServiceImpl"><property name="arrangementDAO" ref="arrangementDAO" /></bean></property></bean></beans>

定义jdbc.properties

#jdbc\u6570\u636e\u5e93\u8fde\u63a5\u914d\u7f6e\u4fe1\u606fjdbc.driver=net.sourceforge.jtds.jdbc.Driverjdbc.url=jdbc\:jtds\:sqlserver\://127.0.0.1\:1433;DatabaseName\=wlynewjdbc.user=sajdbc.password=wlyoa_)*\#\!jdbc.maxActive=100jdbc.maxIdle=30jdbc.maxWait=1000jdbc.defaultAutoCommit=falsejdbc.removeAbandoned=truejdbc.removeAbandonedTimeout=60

 

以上是基于Spring+Struts+Ibatis的配置

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客