当前位置:首页 > 开发 > 编程语言 > Spring > 正文

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

发表于: 2014-02-11   作者:bijian1013   来源:转载   浏览:
摘要: 指定Spring配置文件位置 <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring-dao-bean.xml,/WEB-INF/spring-resources.xml, /WEB-INF/

指定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">
			<bean
				class="org.springframework.cache.ehcache.EhCacheFactoryBean">
				<property name="cacheManager">
					<bean
						class="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">
			<bean
				class="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\u606f
jdbc.driver=net.sourceforge.jtds.jdbc.Driver
jdbc.url=jdbc\:jtds\:sqlserver\://127.0.0.1\:1433;DatabaseName\=wlynew
jdbc.user=sa
jdbc.password=wlyoa_)*\#\!
jdbc.maxActive=100
jdbc.maxIdle=30
jdbc.maxWait=1000
jdbc.defaultAutoCommit=false
jdbc.removeAbandoned=true
jdbc.removeAbandonedTimeout=60

 

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

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

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
命名空间的定义步骤: 第一步:指定命名空间的名称(包括命名空间的缩略名和全名)。如果命名空间的
命名空间的定义步骤: 第一步:指定命名空间的名称(包括命名空间的缩略名和全名)。如果命名空间的
命名空间的定义步骤: 第一步:指定命名空间的名称(包括命名空间的缩略名和全名)。如果命名空间的
1、添加jar 2、web.xml配置 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2
1、添加jar 2、web.xml配置: <?xml version="1.0" encoding="UTF-8"?> <web-app version=
林炳文Evankaka原创作品。转载请注明出处http://blog.csdn.net/evankaka 一、基于@Component注解的
前面几篇学习了Spring的依赖注入,这篇开始学习另一个核心功能——面向切面编程AOP。   通过本文
前面几篇学习了Spring的依赖注入,这篇开始学习另一个核心功能——面向切面编程AOP。   通过本文
这里只做简要的记录,更详细的使用方式,更详细的资料参见spring参考文档(21.15 Code-based Servle
希望越大,失望越大。朋友遇到struts2配置文件未在默认路径下的web.xml问题,我帮忙解决了很久,也
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号