所遇问题如标题,纠结了好久,废话不多说,报错如下
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error updating 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!
遇到spring 无法加载properties时,有个容易被忽略的地方,那就是properties文件中每一行代码结尾后一定不要有空格!
其次在配置Mybatis相关Dao接口Bean时,要注意不要配置sqlSessionFactory属性,改为配置sqlSessionFactoryBeanName,
如下所示,要注意property中 是value 不是 ref
<!-- 配置扫描的Dao接口 自动注入到Spring容器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<property name="basePackage" value="com.cm.dao"></property>
</bean>