在applicationContext.xml中配製DataSource數據庫資源的時候,控制檯報瞭如下異常:
DEBUG [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] -An exception occurred while acquiring a poolable resource. Will retry.
java.sql.SQLException: Access denied for user 'admin'@'localhost' (using password: YES)
spring中的配製如下:
<!-- 加載jdbcInfo.properties文件 -->
<context:property-placeholder location="classpath:jdbcInfo.properties"/>
<!-- 數據庫連接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driverClass}" />
<property name="jdbcUrl" value="${url}" />
<property name="username" value="${user}" />
<property name="password" value="${password}" />
</bean>
jdbcInfo.properties文件配製如下:
driverClass=com.mysql.jdbc.Driver
url=jdbc\:mysql\://localhost\:3306/shop
username=root
password=root
後來百度上有的說是沒有權限,在命令行添加用戶權限;有的說是密碼錯誤,有的說是bug,讓換一個連接池,但都沒有!解決方法:
後來發現當properties文件中中屬性爲username時,纔出現了bug。將jdbcInfo.propertie配製文件的username屬性改爲user,在applicationContext.xml中將${username}響應的改爲${user}即可