在spring 配置文件读数据库参数的properties文件 但是读不到
1.spring的配置文件
classpath*:jdbc.properties
${jdbc.user}
${jdbc.password}
com.mysql.jdbc.Driver
${jdbc.url}
2.jdbc.properties
jdbc.url=jdbc:mysql://localhost:3306/cp?useUnicode=true&charaterEncoding=utf-8
jdbc.user=root
jdbc.password=123456
jdbc.driverClass=com.mysql.jdbc.Driver
3.cp\WebRoot\WEB-INF\classes下有jdbc.properties文件
4.报错:
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: No suitable driver found for ${jdbc.url}
5.结论把
${jdbc.url}当成字符串了 并未读到properties里的数据
解决方案
20
bean id=”propertyConfigurer” class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>
classpath*:jdbc.properties*号去掉
少一个结束标志
CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明spring 配置文件中读取不到properties文件!