Spring context:property-placeholder 一些坑

今天在配置多配置文件的时候偶然发现如果我使用

 1 <context:property-placeholder location="classpath:filePath.properties"/> 这个进行多行编写配置文件的时候会出现后面那个文件出现读取不到的问题
1     <context:property-placeholder location="classpath:jdbc.properties"/>
2     <context:property-placeholder location="classpath:filePath.properties"/>

这样会导致后面那个配置文件失效

原因:Spring 只会加载第一个context:property-placeholder配置后面的文件将不会再次进行加载,所以导致后面的文件读取不到

解决办法:

    <context:property-placeholder ignore-unresolvable="true" location="classpath:jdbc.properties,classpath:filePath.properties"/>

加入一个ignore-unresolvable="true"属性,将文件用,隔开就可以了

  

时间: 2024-08-10 01:55:11

Spring context:property-placeholder 一些坑的相关文章

spring整合mybatis使用&lt;context:property-placeholder&gt;时的坑

背景 最近项目要上线,需要开发一个数据迁移程序.程序的主要功能就是将一个数据库里的数据,查询出来经过一系列处理后导入另一个数据库.考虑到开发的方便快捷.自然想到用spring和mybatis整合一下.甚至用mybatis的自动代码生成,可以省下大量dao层的开发. 整合的坑 之前的项目:以前也有过这种类似的程序,就把spring和mybatis整合的配置直接拿来修改下用.之前的整合配置是这样子的: 1.考虑到数据库url.用户名密码的可配置性,将这些信息放入properties文件.在sprin

初学spring boot踩过的坑

一.搭建spring boot环境 maven工程 pom文件内容 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-

Spring context的refresh函数执行过程分析

今天看了一下Spring Boot的run函数运行过程,发现它调用了Context中的refresh函数.所以先分析一下Spring context的refresh过程,然后再分析Spring boot中run的流程. 首先我们找到spring-context组件的AbstractApplicationContext类下的refresh函数: @Override public void refresh() throws BeansException, IllegalStateException

Spring &lt;context:annotation-config&gt; 和 &lt;context:component-scan&gt;诠释及区别

<context:annotation-config> 和 <context:component-scan>的区别 <context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注解. <context:component-scan>除了具有<context:annotation-config>的功能之外,<conte

部署spring boot + Vue遇到的坑(权限、刷新404、跨域、内存)

部署spring boot + Vue遇到的坑(权限.刷新404.跨域.内存) 项目背景是采用前后端分离,前端使用vue,后端使用springboot. 工具 工欲善其事必先利其器,我们先找一个操作Linux系统的工具极力推荐FinalShell. 一眼看过去是不是感觉很方便,对内存.CPU的监控也可以实时看到,访问目录更是方便,对于Linux小白来说简直是神兵利器. 好了,我要开始入坑了. 问题一:权限不够 把vue包放到tomcat->webapps->ROOT目录下. 启动tomcat:

Spring &lt;context:annotation-config/&gt; 解说(转)

在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是式地向 Spring 容器注册 AutowiredAnnotationBeanPostProcessor.CommonAnnotationBeanPostProcessor. PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostPr

Spring.NET 配置错误【Spring.Context.Support.ContextRegistry”的类型初始值设定项引发异常。】

用VS 2013 ,配置Spring后,运行时出现如下错误: Spring.Context.Support.ContextRegistry”的类型初始值设定项引发异常. 原因:App.config配置文件,startup放到文件前了. 解决方法:将startup放到最后,问题没有了. <?xml version="1.0" encoding="utf-8"?><configuration> <configSections> <

Spring &lt;context:component-scan&gt;标签属性 use-default-filters 以及子标签 include-filter使用说明

Spring <context:component-scan>标签作用有很多,最基本就是 开启包扫描,可以使用@Component.@Service.@Component等注解: 今天要作为发现,记录该标签的属性 use-default-filters 以及子标签 include-filter使用方式 : use-default-filters 默认true,默认会扫描@Component.@Controller.@Service.@Repository注解,因为这些注解都可以说是@Compo

spring in action 学习十一:property placeholder Xml方式实现避免注入外部属性硬代码化

这里用到了placeholder特有的一个语言或者将表达形式:${},spring in action 描述如下: In spring wiring ,placeholder values are property names wrapped with ${...},as an exampl,you can resolve the constructor arguments for a BlankDisc in xml like this : <bean id="sgtPeppers&qu