Oracle 数据源的配置。在Spring环境中


第一种 采用JDBC配置文件。


<?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:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:flex="http://www.springframework.org/schema/flex"
	xsi:schemaLocation="       
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd       
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd       
      http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd       
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd       
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      http://www.springframework.org/schema/flex
      http://www.springframework.org/schema/flex/spring-flex-1.0.xsd
      http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd"
	default-autowire="byName">
	
	
	<context:annotation-config />
	
	<!-- 导入属性配置文件 --> 
	<context:property-placeholder location="/WEB-INF/conf/jdbc.properties" />
	<!-- 数据库的配置 ,dbcp连接池 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
	    <property name="driverClassName">
	      <value>${jdbc.driverClassName}</value>  
	   </property>
	    <property name="url">
	      <value>${jdbc.url}</value>  
	   </property>
	    <property name="username">
	      <value>${jdbc.username}</value>  
	   </property>
	    <property name="password">
	      <value>${jdbc.password}</value>  
	   </property>
	   <property name="maxActive"><value>50</value></property>  
       <property name="maxIdle"><value>20</value></property> 
       <property name="maxWait"><value>5000</value></property>	   
	</bean>	

	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- 需要事务控制的业务方法配置 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="get*" read-only="true" />
			<tx:method name="find*" read-only="true" />
			<tx:method name="query*" read-only="true" />
			<tx:method name="select*" read-only="true" />
			<tx:method name="count*" read-only="true" />
			<tx:method name="*" rollback-for="Exception" />
		</tx:attributes>
	</tx:advice>

	<!-- 事务控制拦截器 -->
	<aop:config proxy-target-class="true">
		<aop:advisor
			pointcut="execution(* *..service.impl.*(..)) or execution(* *..service..*ServiceImpl.*(..))"
			advice-ref="txAdvice" />
	</aop:config>
	<bean id="sqlSessionFactory"
		class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="configLocation"
			value="/WEB-INF/conf/mybatis/mybatis-config.xml" />
		<property name="mapperLocations"
			value="classpath*:/org/topcheer/biz/sys/xml/*.xml" />
		<property name="dataSource" ref="dataSource" />
	</bean>

</beans>



第二种 : JNDI:

<?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:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:flex="http://www.springframework.org/schema/flex"
	xsi:schemaLocation="       
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd       
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd       
      http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd       
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd       
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      http://www.springframework.org/schema/flex
      http://www.springframework.org/schema/flex/spring-flex-1.0.xsd
      http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd"
	default-autowire="byName">
	
	
	<context:annotation-config />
	

	<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName">
			<value>KINGHONG</value>
		</property>
	</bean>
	
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
	</bean>
	
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- 需要事务控制的业务方法配置 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="get*" read-only="true" />
			<tx:method name="find*" read-only="true" />
			<tx:method name="query*" read-only="true" />
			<tx:method name="select*" read-only="true" />
			<tx:method name="count*" read-only="true" />
			<tx:method name="*" rollback-for="Exception" />
		</tx:attributes>
	</tx:advice>

	<!-- 事务控制拦截器 -->
	<aop:config proxy-target-class="true">
		<aop:advisor
			pointcut="execution(* *..service.impl.*(..)) or execution(* *..service..*ServiceImpl.*(..))"
			advice-ref="txAdvice" />
	</aop:config>
	<bean id="sqlSessionFactory"
		class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="configLocation"
			value="/WEB-INF/conf/mybatis/mybatis-config.xml" />
		<property name="mapperLocations"
			value="classpath*:/org/topcheer/biz/sys/xml/*.xml" />
		<property name="dataSource" ref="dataSource" />
	</bean>


	

</beans>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值