码迷,mamicode.com
首页 > 数据库 > 详细

spring整合mybaits时Connections could not be acquired from the underlying database!异常解决

时间:2014-12-14 13:22:11      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:spring和mybatis整合

<?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:mvc="http://www.springframework.org/schema/mvc"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
		 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
	
	<!-- 使用注解自动创建bean,设置bean所在的包 -->
	<context:component-scan base-package="com.leo.dao,com.leo.service" />
	
	<!-- @Autowired自动装配 
	<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
	-->
	
	<!-- 配置数据源 -->
	<!-- <context:property-placeholder location="classpath:db.properties"/> -->
	<bean id = "propertyConfigurer"  class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
	    <property  name ="location"  value ="com/leo/resources/db.properties"/>
        </bean>
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${driverClass}"></property>
		<property name="jdbcUrl" value="${url}"></property>
		<property name="user" value="${username}"></property>
		<property name="password" value="${password}"></property>
	</bean>
	
	<!-- 创建SqlSessionFactory-->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
	
	<!-- 指定数据源 -->
		<property name="dataSource" ref="dataSource" />
		<property name="typeAliasesPackage" value="com.leo.entity"></property>
		<property name="mapperLocations" value="classpath*:com/leo/dao/*Mapper.xml" />
	</bean>
	
	<!-- 配置事务 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	
	<!-- 映射接口 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.leo.dao" />
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
	</bean>


</beans>


当我使用这句读取数据源文件时,就总是找不到

<context:property-placeholder location="classpath:db.properties"/>

换成

<bean id = "propertyConfigurer"  class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
	    <property  name ="location"  value ="com/leo/resources/db.properties"/>
</bean>
就可以,我也不知道为什么?

希望可以获得帮助,知道的人可以帮忙解答一下,

spring整合mybaits时Connections could not be acquired from the underlying database!异常解决

标签:spring和mybatis整合

原文地址:http://blog.csdn.net/liuao107329/article/details/41923971

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!