当前位置: 代码迷 >> Web前端 >> spring资料基础配置
  详细解决方案

spring资料基础配置

热度:347   发布时间:2013-08-10 21:14:06.0
spring文件基础配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:info.properties</value>
			</list>
		</property>
	</bean>//数据源
	<bean id="dataSource"
		class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close" dependency-check="none">
		<property name="driverClass">
			<value>${jdbc.driver}</value>
		</property>
		<property name="jdbcUrl">
			<value>${jdbc.url}</value>
		</property>
		<property name="user">
			<value>${jdbc.username}</value>
		</property>
		<property name="password">
			<value>${jdbc.password}</value>
		</property>
		<property name="acquireIncrement">
			<value>${c3p0.acquireIncrement}</value>
		</property>
		<property name="initialPoolSize">
			<value>${c3p0.initialPoolSize}</value>
		</property>
		<property name="minPoolSize">
			<value>${c3p0.minPoolSize}</value>
		</property>
		<property name="maxPoolSize">
			<value>${c3p0.maxPoolSize}</value>
		</property>
		<property name="maxIdleTime">
			<value>${c3p0.maxIdleTime}</value>
		</property>
		<property name="idleConnectionTestPeriod">
			<value>${c3p0.idleConnectionTestPeriod}</value>
		</property>
		<property name="maxStatements">
			<value>${c3p0.maxStatements}</value>
		</property>
		<property name="numHelperThreads">
			<value>${c3p0.numHelperThreads}</value>
		</property>
	</bean>
	
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					${hibernate.dialect}
				</prop>
				<prop key="hibernate.show_sql">
					${hibernate.show_sql}
				</prop>
				<!-- <prop key="hibernate.hbm2ddl.auto">update</prop> -->
				<prop key="hibernate.jdbc.fetch_size">
					${hibernate.jdbc.fetch_size}
				</prop>
				<prop key="hibernate.jdbc.batch_size">
					${hibernate.jdbc.batch_size}
				</prop>
				<prop key="hibernate.connection.provider_class">
					net.sf.hibernate.connection.C3P0ConnectionProviderc3p0
				</prop>
				<!-- <prop key="hibernate.cache.provider_class">
					org.hibernate.cache.EhCacheProvider
				</prop>
				<prop key="hibernate.cache.use_second_level_cache">true</prop>
				<prop key="hibernate.cache.use_query_cache">true</prop>
				<prop key="hibernate.cache.provider_class">net.sf.hibernate.connection.C3P0ConnectionProviderc3p0</prop>
				<prop key="hibernate.cache.provider_configuration_file_resource_path">
					/ehcache-hibernate.xml
				</prop> -->
			</props>
		</property>
		<property name="eventListeners">
                <map>
                    <entry key="merge">
                       <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
                    </entry>
                </map>
        </property>		
		<property name="mappingDirectoryLocations">
			<list>				
				<value>classpath:com/web/sys/vo/</value>
				<value>classpath:com/web/bd/vo/</value>
				<value>classpath:com/web/event/vo/</value>
			</list>
		</property>
	</bean>
	
		
	<bean id="jdbcTemplate"	class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
	</bean>//jdbc   sql
	
	 <!--transactionManager-->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	<!-- 定义事务代理bean的模板 -->
	<bean id="txProxyTemplate" lazy-init="true" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
		<property name="transactionManager">
			<ref bean="transactionManager" />
		</property>
		<property name="transactionAttributes">
			<props>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
				<prop key="remove*">PROPAGATION_REQUIRED</prop>
				<prop key="update*">PROPAGATION_REQUIRED</prop>
				<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="*">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>	
</beans>



    <bean id="hibernateDaoSupport" abstract="true">		
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

<!-- sys start -->
	<bean id="opinfoDao" class="com.web.sys.dao.hibernate.OpinfoDaoHibernate" parent="hibernateDaoSupport"/>	



 <!-- sys start -->
    <bean id="jtcyqkService" parent="txProxyTemplate">
		<property name="target">
			<bean class="com.web.sys.service.impl.JtcyqkServiceImpl"/>
		</property>
	</bean>
  相关解决方案