Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}错误
来源:互联网 发布:ext js 学多久 编辑:程序博客网 时间:2024/06/03 16:16
今天在MyEclipse搭建spring框架,通过自动生成spring框架,布好DAO层还有Service层后,还导入了单元测试,没想到在测试时出现了
Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}错误
具体代码如下:
test类
import javax.annotation.Resource;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import Service.AccountService;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration("classpath:applicationContext.xml")public class test {@Resource(name="accountService")private AccountService accountService;@Testpublic void demo1(){accountService.transfer("aaa", "bbb", 200d);}}service层
<tx:annotation-driven transaction-manager="transactionManager" /><bean id="accountService" class="Service.AccountServiceImpl"></bean>
DAO层
<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true" /><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="${jdbc.driverClass}"/><property name="jdbcUrl" value="${jdbc.url}" /><property name="user" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /></bean><bean id="accountDao" class="Dao.AccountDaoImpl"> <property name="dataSource" ref="dataSource"></property></bean>数据库
jdbc.properties 文件已导入,设置好数据库的键值对、
然后在测试时出现该错误,思考一下,可能是该数据库文件的键名称与DAO层的dataSource不对应,或者是名称打错
开始调试bug-----------------------------------
我先删除了DAO层的第一行
<property name="driverClass" value="${jdbc.driverClass}"/>
然后错误信息就变了
Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.url} 错误
证明不是名称打错,应该是文件jdbc.properties导入失败-------------------------
再次寻找原因
网上说修改一下
<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true" />在其后面加上 ignore-unresolvable="true" 属性,测试后还是同样的错误---------------------------------------
再次寻找原因
在网上找到
可能是Spring容器的配置问题
Spring容器采用反射扫描的发现机制,在探测到Spring容器中有一个org.springframework.beans.factory.config.PropertyPlaceholderConfi
而这个基于命名空间的配置,其实内部就是创建一个PropertyPlaceholderConfi
PropertyPlaceholderConfi
- Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}错误
- Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}
- 报错Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}
- Could not resolve placeholder 'driverClassName' in string value "${driverClassName}"
- 错误笔记之Could not resolve placeholder 'jdbc.driver' in string value "${jdbc.driver}"
- Could not resolve placeholder 'master.jdbc.url' in string value "${master.jdbc.url}"
- Could not resolve placeholder 'jdbc.username' in string value "${jdbc.username}"
- Could not resolve placeholder 'jdbc.url' in string value "${jdbc.url}"
- Could not resolve placeholder 'jdbc.url' in string value "${jdbc.url}"
- Could not load JDBC driver class [${driverClassName}]
- Circular placeholder reference 'jdbc.driverClassName' in property definitions
- $Value{}ntException: Could not resolve placeholder 'KEY' in string value "${
- Could not resolve placeholder 'CUST_INDUSTORY' in string value "${CUST_INDUSTORY}"
- Could not resolve placeholder 'driver' in string value "${driver}"
- 解决 IllegalArgumentException: Could not resolve placeholder in string value "${XXXXXX}"
- Could not resolve placeholder 'driverClasss' in string value "${driverClasss}"
- 解决 IllegalArgumentException: Could not resolve placeholder in string value "${XXXXXX}"
- sharding jdbc--Cloud not resolve placeholder … in string value …?
- 不要慌,你只有三大问题
- java的8种排序算法实现
- LeetCode 553. Optimal Division (除法划分,算法)
- 基于easyPR和openalpr的车牌识别研究
- ehwrthertherh
- Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}错误
- 迪拜机器人警察上岗 精通6种语言
- 第 15 章 MySQL分布式应用
- .分析以下需求,并用代码实现 1.定义List集合,存入多个字符串 2.删除集合元素字符串中包含0-9数字的字符串 只要字符串中包含0-9中的任意一个数字就需
- 存储过程的优缺点及适宜使用的场合详解
- C#转换Base64编码,解码的URL
- Side-Menu.Android的应用
- 天天写业务代码的程序员怎么成为大牛
- 理解ROC与AUC