Could not resolve placeholder 'jdbc.url' in string value "${jdbc.url}"
2016-08-12 23:11
555 查看
报错信息:
这个Bug,一般的都会说,你的*.properties 属性文件是否存在,文件中,名称是否与applicationcontext.xml 中的文件名称是否一致,一开始,我也是天真的这么认为的,然后还认认真真的对比了半天,没毛病啊。
下边是properties 属性文件
对比一下,正确。而且工程的jar包中也包含JDBC的。
后来,找了半天,经过大神的指导,找到了原因:
Could not resolve placeholder就是eclipse在运行过程中要加在properties文件中的jdbc.url这个配置项,由于没有找到无法加在,就会报这个错。
解决方法:
在Spring 3中可以用如下方式解决,增加ignore-unresolvable="true"属性,注意必须都要加上
<context:property-placeholder location="xxx.properties" ignore-unresolvable="true" />
<context:property-placeholder location="yyy.properties" ignore-unresolvable="true" />
在Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,此时可以改用PropertyPlaceholderConfigurer。其实<context:property-placeholder location="xxx.properties" ignore-unresolvable="true" />与下面的配置是等价的
<bean id="XX" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="xxx.properties" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
OK,可以了。
<span style="font-family:Microsoft YaHei;font-size:14px;"><span style="font-family:Microsoft YaHei;font-size:14px;">严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in file [G:\Computer\Java\MyObject\taotao\taotao-manager\taotao-manager-web\target\classes\spring\applicationContext-dao.xml]: Could not resolve placeholder 'jdbc.url' in string value "${jdbc.url}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'jdbc.url' in string value "${jdbc.url}" at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:211) at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.processProperties(PropertySourcesPlaceholderConfigurer.java:180) at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:155) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:162) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744)</span></span>
这个Bug,一般的都会说,你的*.properties 属性文件是否存在,文件中,名称是否与applicationcontext.xml 中的文件名称是否一致,一开始,我也是天真的这么认为的,然后还认认真真的对比了半天,没毛病啊。
下边是properties 属性文件
<span style="font-family:Microsoft YaHei;font-size:14px;">jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://192.168.25.134:3306/SCTest?characterEncoding=utf-8 jdbc.username=root jdbc.password=root</span>
对比一下,正确。而且工程的jar包中也包含JDBC的。
后来,找了半天,经过大神的指导,找到了原因:
Could not resolve placeholder就是eclipse在运行过程中要加在properties文件中的jdbc.url这个配置项,由于没有找到无法加在,就会报这个错。
解决方法:
在Spring 3中可以用如下方式解决,增加ignore-unresolvable="true"属性,注意必须都要加上
<context:property-placeholder location="xxx.properties" ignore-unresolvable="true" />
<context:property-placeholder location="yyy.properties" ignore-unresolvable="true" />
在Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,此时可以改用PropertyPlaceholderConfigurer。其实<context:property-placeholder location="xxx.properties" ignore-unresolvable="true" />与下面的配置是等价的
<bean id="XX" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="xxx.properties" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
OK,可以了。
相关文章推荐
- Could not resolve placeholder 'master.jdbc.url' in string value "${master.jdbc.url}"
- Could not resolve placeholder 'jdbc.url' in string value "${jdbc.url}"
- Could not resolve placeholder 'jdbc.url' in string value "${jdbc.url}"
- Could not resolve placeholder 'jdbc.username' in string value "${jdbc.username}"
- Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}错误
- 错误笔记之Could not resolve placeholder 'jdbc.driver' in string value "${jdbc.driver}"
- 启动错误:Could not resolve placeholder 'spring.datasource.url' in value "${spring.datasource.url}"
- Could not resolve placeholder 'driverClassName' in string value "${driverClassName}"
- Could not resolve placeholder 'redis.pool.maxTotal' in string value "${redis.pool.maxTotal}
- Could not resolve placeholder 'driver' in string value "${driver}"
- 解决 IllegalArgumentException: Could not resolve placeholder in string value "${XXXXXX}"
- 解决 IllegalArgumentException: Could not resolve placeholder in string value "${XXXXXX}"
- $Value{}ntException: Could not resolve placeholder 'KEY' in string value "${
- 解决 IllegalArgumentException: Could not resolve placeholder in string value "${XXXXXX}"
- spring cloud config---Could not resolve placeholder 'foo' in string value "${foo}"
- Could not resolve placeholder 'driverClasss' in string value "${driverClasss}"
- Could not resolve placeholder '***' in string value "${****}"
- Could not resolve placeholder 'redis.pool.maxTotal' in string value "${redis.pool.maxTotal}"
- Could not resolve placeholder 'mail.from' in string value "${mail.from}" 报错原因
- 解决 Could not resolve placeholder 'some.var.name' in string value