spring-mybatis configured to use the database connection leads not obtain jdbc.properties

Use jdbc data source arranged spring-mybatis configuration, the card

Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@83ecde7] was not registered for synchronization because synchronization is not active

Do not run, after waiting for some time report

Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2fc16b69]
十月 07, 2015 6:05:23 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [SpringMVC] in context with path [/lemon] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
### The error may exist in file [F:\Program Files (x86)\Apache\apache-tomcat-myeclipse\webapps\lemon\WEB-INF\classes\com\lemengxiangju\xiangju\mapper\AdmissionPlanMapper.xml]
### The error may involve com.lemengxiangju.xiangju.dao.AdmissionPlanMapper.selectAll
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!] with root cause
com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.

error.

Profile
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:p="http://www.springframework.org/schema/p"
    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-4.0.xsd      
                        http://www.springframework.org/schema/context      
                        http://www.springframework.org/schema/context/spring-context-4.0.xsd      
                        http://www.springframework.org/schema/mvc      
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <bean id="dataSource" destroy-method="close"
        class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${driverClassName}"></property>
        <property name="jdbcUrl" value="${url}"></property>
        <property name="user" value="${username}"></property>
        <property name="password" value="${password}"></property>
        <property name="initialPoolSize" value="${initialSize}"></property>
        <property name="maxPoolSize" value="${maxIdle}"></property>
        <property name="maxStatements" value="${maxActive}"></property>
    </bean>

    <!-- 加载jdbc -->
    <context:property-placeholder location="classpath:properties/jdbc.properties" />

    <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:config/mybatis-config.xml"></property>

        <!-- 自动扫描mapping.xml文件 -->
        <property name="mapperLocations"
            value="classpath:com/lemengxiangju/xiangju/mapper/*Mapper.xml"></property>

    </bean>

    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.lemengxiangju.xiangju.dao" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>


    <!-- 声明式事务管理 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
</beans>  

jdbc.properties

# MySQL JDBC
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/kindergarten?useSSL=true
username=root
password=123456
initialSize=10
maxActive=50
maxIdle=25
minIdle=6

Solution:
The spring-mybatis the data source configuration change

<bean id="dataSource" destroy-method="close"
        class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="${url}"></property>
        <property name="user" value="root"></property>
        <property name="password" value="${password}"></property>
        <property name="initialPoolSize" value="${initialSize}"></property>
        <property name="maxPoolSize" value="${maxIdle}"></property>
        <property name="maxStatements" value="${maxActive}"></property>
    </bean>

That is, a user name and driver class written directly. Is not configured with the properties.

Specific reasons not clear, probably because of the configuration file to read properties resulting in connection timeouts. Back-end database connection is not successful.

Guess you like

Origin blog.csdn.net/taoism_jerry/article/details/78170781