【转】Spring项目启动报"Could not resolve placeholder"解决方法

问题的起因:

  除去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

原文地址:https://www.cnblogs.com/modou/p/10015648.html

时间: 2024-10-12 01:21:01

【转】Spring项目启动报"Could not resolve placeholder"解决方法的相关文章

spring项目启动报错BeanFactory not initialized or already closed

spring项目启动的时候报如下错误: java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContextat org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanF

mysql登陆启动报错 ERROR 2002 (HY000) 解决方法

报错信息 登陆数据库报错:` ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory")` 重启服务报错:Job for mariadb.service failed because the control process exited with error code. See &quo

Eureka Server项目启动报错处理

Eureka Server项目启动报错处理 Eureka是一个服务发现组件,提供服务注册.发现等注册中心功能,使用spring boot启动eureka应用时出现报错: 20:36:17.646 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application run failed java.lang.NoSuchMethodError: org.springframework.boot.builder.

SpringBoot项目启动报错:java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

.   ____          _            __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/  ___)| |_)| | | | | || (_| |  ) ) ) )  '  |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Sprin

tomcat下部署了多个项目启动报错java web error:Choose unique values for the &#39;webAppRootKey&#39; context-param in your web.xml files

应该是tomcat下部署了多个项目且都使用log4j. <!--如果不定义webAppRootKey参数,那么webAppRootKey就是缺省的"webapp.root".但最好设置,以免项目之间的名称冲突. 定义以后,在Web Container启动时将把ROOT的绝对路径写到系统变量里. 然后log4j的配置文件里就可以用${webName.root }来表示Web目录的绝对路径,把log文件存放于webapp中. 此参数用于后面的“Log4jConfigListener”

spring Boot启动报错Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes

spring boot 启动报错如下 org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure

Sping Cloud项目启动报A component required a bean of type &#39;com.tianyan.bbc.dao.SecurityUserBaseMapper&#39; that could not be found.

项目构建正常,启动和Debug报以下错误: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2018-12-14 09:49:32.038 [main] ERROR o.s.b.diagnostics.LoggingFailureAnalysisReporter - ***************************

1.Spring项目启动时,加载相关初始化配置

Spring项目启动时,会加载一些常用的配置: 1.加载spring上下文 SpringApplicationContextUtils.initApplicationContext(event.getServletContext()); 2.加载属性文件 EsbCommsUtils.initComms(event.getServletContext()); 1 public class EsbCommsUtils { 2 3 private static Log logger = LogFact

springboot项目启动报错 url&#39; attribute is not specified and no embedded datasource could be configured

报错相关信息: 2019-07-22 17:12:48.971 ERROR 8312 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not