今天配置SSM导入db.properties文件来配置数据库时 报了Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 错误提示我数据库连接失败,上网查询原因确定是连接参数问题,但是我反复检查没有出错 db.properties
driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=utf8 username=root pwd=rootspring-dao.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> <!--1.关联数据库配置文件--> <context:property-placeholder location="classpath:db.properties"></context:property-placeholder> <!--2.spring 配置连接池,数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${driver}"></property> <property name="jdbcUrl" value="${url}"/> <property name="user" value="${username}"></property> <property name="password" value="${pwd}"></property> <property name="maxPoolSize" value="30"/> <property name="minPoolSize" value="10"/> <!--关闭连接后不自动commit--> <property name="autoCommitOnClose" value="false"/> <!--超时时间--> <property name="checkoutTimeout" value="10000"/> <!--连接失败时重试次数--> <property name="acquireRetryAttempts" value="2"/> </bean> <!--整合spring与mybatis--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="classpath:mybatis-config.xml"></property> </bean> <!--配置动态扫描dao接口包,动态将接口注入到spring中--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!--注入sqlSessionFactory--> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> <!--配置扫描包--> <property name="basePackage" value="com.xzf.dao"/> </bean> </beans>在多次排错后发现错误时在db.properties文件中不能使用username=root参数,会导致无法正确解析 改为user=root问题解决,这个天坑花费了我好一个小时,晕了