1.问题的起因:
除去properites文件路径错误、拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderConfigurer或者多个<context:property-placeholder>的原因。
比如我有一个dao.xml读取dbConnect.properties,还有一个dfs.xml读取dfsManager.properties,然后web.xml统一load这两个xml文件,就导致该问题的出现。
解决方法:
(1)在Spring 3.0中,可以写
Xml代码
<context:property-placeholder location="xxx.properties" ignore-unresolvable="true" />
<context:property-placeholder location="yyy.properties" ignore-unresolvable="true" />
注意两个都要加上ignore-unresolvable="true",一个加另一个不加也是不行的
(2)在Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,此时可以改用PropertyPlaceholderConfigurer。其实<context:property-placeholder location="xxx.properties" ignore-unresolvable="true" />与下面的配置是等价的
配置内容:
<bean id="随便" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="xxx.properties" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
正因为如此,写多个PropertyPlaceholderConfigurer不加ignoreUnresolvablePlaceholders属性也是一样会出"Could not resolve placeholder"。
虽然两者是的等价的,但估计大家还是喜欢写<context:property-placeholder>多一些,毕竟简单一些嘛。所以如果是Spring 3.0,直接用解决方案(1)再简单不过了;如果是Spring 2.5,需要费点力气改写成PropertyPlaceholderConfigurer
代码调用顺序
1.web.xml 中
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/context-servlet.xml</param-value>
</context-param>
2.context-servlet.xml中
解决问题的代码
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="1" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>/WEB-INF/eaching.properties</value>
<value>/WEB-INF/jdbc.properties</value>
</list>
</property>
</bean>
3.<import resource="config/applicationContext-profile.xml"/>中
<beans profile="dev">
<context:property-placeholder location="classpath*:config/*.properties,file:${sucang.root}/WEB-INF/config/dev/*.properties,classpath*:dev/*.properties"/>
<import resource="classpath*:dev/applicationContext-*.xml"/>
</beans>
<beans profile="test">
<context:property-placeholder location="classpath*:config/*.properties,file:${sucang.root}/WEB-INF/config/test/*.properties,classpath*:test/*.properties"/>
<import resource="classpath*:test/applicationContext-*.xml"/>
</beans>
<beans profile="prod">
<context:property-placeholder location="classpath*:config/*.properties,file:${sucang.root}/WEB-INF/config/prod/*.properties,classpath*:prod/*.properties"/>
<import resource="classpath*:prod/applicationContext-*.xml"/>
</beans>
分享到:
相关推荐
按官方配置好了 developer.... Could not resolve com.huawei.agconnect 解决方法:把相应的插件用本地化安装 agconnect-crash-symbol-lib-1.6.1.300.jar agconnect-apms-plugin-1.6.1.300.jar agcp-1.6.1.300.jar。
Could not resolve all dependencies for configuration ‘:classpath’. Could not resolve com.android.tools.build:gradle:2.1.2. ………. 等6个error 上网百度csdn,结果试下各种方法,依旧没用。 搞了一天,...
myeclipse创建maven工程报错 Could not resolve
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all artifacts for configuration ‘:classpath’. 提示错误:Read Time out ...
hive 开发UDF 使用maven工程 引发jar包缺失 hive 开发UDF 使用maven工程 引发jar包缺失
主要介绍了解决Unable to access 'https://gitee.com/自己的项目/': Could not resolve host: gitee.com问题,需要的朋友可以参考下
[INFO] ———————————————————————— [INFO] Reactor Summary for demo 0.0.1-SNAPSHOT: [INFO] [INFO] demo ……………………………………….. FAILURE [18:18 min] [INFO] admin-service ...
Error:Could not resolve all files for configuration ‘:app:debugCompileClasspath’. > Could not resolve com.android.support:appcompat-v7:26.0.0-beta1. Required by: project :app > Could not ...
$_SERVER,$_HTTP,__FILE__
新建maven项目时报Could not resolve archetype org.apache.maven.archetypes
Microsoft OLE DB Provider for ODBC Drivers 错误'80040e4d'[Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve the connect identifier specified. 使用PL-SQL Developer能连接上Oracle,但是ASP+ODBC连不上...
Eclipse Maven 创建Web 项目报错 Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webap 之前找了很久才找到了,传上来更大家共享下,希望对大家有帮助,欢迎下载或者永久保存。
安卓调取usb摄像头的工具类,包含了之前版本删除掉的类,解决:libusbcamera@debug/compileClasspath': Could not resolve com.serenegiant:common:1.5.20.报错问题,需要配合repository文件夹使用
Could not resolve all files for configuration ':jcore-react-native:lintClassPath'. > Could not download groovy-all.jar (org.codehaus.groovy:groovy-all:2.4.15) > Could not get resource '
`org.hibernate.QueryException: could not resolve property: isStudent of: com.zluo.hibernate.po.User [from com.zluo.hibernate.po.User u where u.isStudent = ?]` 当时就在想怎么会出现这个错误呢,
build时出现错误Could not resolve nl.eveoh:gradle-aspectj:1.6。将此文件放入此目录下即可.m2\repository\nl\eveoh\gradle-aspectj\1.6
网上下载的开源SSL服务器扫描代码。 依赖与openssl库。 超级好用啊,精华之作。
asm-analysis-5.0.3.jar;asm-analysis-5.0.3.jar;asm-analysis-5.0.3.jar
Could not resolve dependencies for project ****:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: com.sun.jdmk:jmxtools:jar:1.2.1, com.sun.jmx:jmxri:jar:1.2.1: Could not transfer ...