首页 > 代码库 > org.springframework.beans.factory.BeanDefinitionStoreException异常
org.springframework.beans.factory.BeanDefinitionStoreException异常
1、下面是我遇到的异常信息:
2017-03-25 18:01:11,322 [localhost-startStop-1] [org.springframework.web.context.ContextLoader]-[ERROR] Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException:
Invalid bean definition with name ‘dataSource‘ defined in file [C:\Users\Aaron\workspace\HT\target\classes\spring\applicationContext.xml]:
Could not resolve placeholder ‘jdbc.driver‘ in string value "${jdbc.driver}";
nested exception is java.lang.IllegalArgumentException:
Could not resolve placeholder ‘jdbc.driver‘ in string value "${jdbc.driver}"
2、异常信息中文翻译:
Context initialization failed:
环境初始化失败
BeanDefinitionStoreException:
这是一个异常对象:java bean 定义、注入异常
Invalid bean definition with name ‘dataSource‘ defined in file:
无效的 java bean 定义,使用文件C:\Users\Aaron\workspace\HT\target\classes\spring\applicationContext.xml 为 dataSourece 类定义属性时出错:
Could not resolve placeholder ‘jdbc.driver‘ in string value "${jdbc.driver}";
不能解析占位符 ‘jdbc.driver‘ in string value "${jdbc.driver}";
IllegalArgumentException
非法参数异常
3、查找错误
3.1 在 applicationContext.xml 里有如下配置:
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
<property name="driverClassName" value="http://www.mamicode.com/${jdbc.driver}"/>
3.2 在 db-mysql.properties 里有如下配置:
jdbc.driverClassName=com.mysql.jdbc.Driver
3.3 value的变量名为jdbc.driver,但在properties里配置的却是jdbc.driverClassName
4、解决办法
修改db-mysql.properties文件如下:
jdbc.driver=com.mysql.jdbc.Driver
org.springframework.beans.factory.BeanDefinitionStoreException异常