一、只读取单个 properties 文件

1、在 spring 的配置文件中,加入
引入命名空间:
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util
       http://www.springframework.org/schema/util/spring-util-3.0.xsd"
 
内容中写入
<util:properties id="propertiesReader" location="classpath:test.properties" /> 
 
2、在类中需要注入的属性实现 setter 和 getter 方法。
 
3、在 setter 方法前,添加 @Value 注解
@Value("#{propertiesReader[propertiesName]}")
propertiesName 为 properties 文件中的键。这样,在容器启动过程中, Spring 将自动注入值。
 
二、读取多个 properties 文件
与上类似,只是在配置文件写入的内容不同。
<bean id="propertiesReader"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:param.properties</value>
<value>classpath:base.properties</value>
</list>
</property>
</bean>

spring注解中使用properties文件的更多相关文章

  1. Spring MVC 中使用properties文件

    首先要搭建Spring mvc的环境,然后开始properties文件里的配置: 第一步:在springcontext中注入properties,具体路径自己调整 <bean id=" ...

  2. spring配置中,properties文件以及xml文件配置问题

    spring方便我们的项目快速搭建,功能强大,自然也会是体系复杂! 这里说下配置文件properties管理的问题. 一些不涉及到代码逻辑,仅仅只是配置数据,可以放在xxxx.properties文件 ...

  3. spring 配置文件中使用properties文件 配置

    配置Bean载入properties文件: <bean id="propertyPlaceholderConfigurer" class="org.springfr ...

  4. spring boot 在框架中注入properties文件里的值(Spring三)

    前一篇博客实现了打开第一个页面 链接:https://blog.csdn.net/qq_38175040/article/details/105709758 本篇博客实现在框架中注入propertie ...

  5. 五种方式让你在java中读取properties文件内容不再是难题

    一.背景 最近,在项目开发的过程中,遇到需要在properties文件中定义一些自定义的变量,以供java程序动态的读取,修改变量,不再需要修改代码的问题.就借此机会把Spring+SpringMVC ...

  6. Spring Boot中的Properties

    文章目录 简介 使用注解注册一个Properties文件 使用属性文件 Spring Boot中的属性文件 @ConfigurationProperties yaml文件 Properties环境变量 ...

  7. Spring bean中的properties元素内的name 和 ref都代表什么意思啊?

    <bean id="userAction" class="com.neusoft.gmsbs.gms.user.action.UserAction" sc ...

  8. Spring依赖注入的方式、类型、Bean的作用域、自动注入、在Spring配置文件中引入属性文件

    1.Spring依赖注入的方式 通过set方法完成依赖注入 通过构造方法完成依赖注入 2.依赖注入的类型 基本数据类型和字符串 使用value属性 如果是指向另一个对象的引入 使用ref属性 User ...

  9. eclipse中编辑properties文件无法看到中文

    如果在eclipse中编辑properties文件无法看到中文则参考“Eclipse开发环境配置-indigo.docx”添加propedit插件.

随机推荐

  1. 微信公共服务平台开发(.Net 的实现)9-------处理二维码

    今天我们来共同学习一下微信公共服务平台中一个重要内容---二维码扫描.众所周知二维码目前应用范围很广,在这里不再叙述背景了,但是值得一提的是目前大家手机上面应用的二维码扫描工具是支持的都是QR码和PD ...

  2. JavaScript Design Patterns: Mediator

    The Mediator Design Pattern The Mediator is a behavioral design pattern in which objects, instead of ...

  3. TP复习

    第一课,三步骤 1,.名称   2.路径 3.引用核心文件 4,.公用的可以建立public  upload css 等 第二课 uRL四中模式 ~ActionClass.php 一.什么是MVC / ...

  4. Ubuntu下VSFTPD(六)(常见FTP命令及其功能) (

    常见FTP命令及其功能  FTP 命令 功能  FTP 命令 功能  ls 显示服务器上的目录 ls [remote-dir][local-file] 显示远程目录remote-dir,并存入本地文件 ...

  5. 代码片段 - JavaScript 求时间差

    // 求时间差1(时间差不能超过一天) function timeDifference1(startTime, endTime) { let times = endTime.getTime() - s ...

  6. 为rm命令增加回收站功能

    rm是个强大的命令,特别是rm -rf有时候强大到让你欲哭无泪,当你想清除当前目录下的所有文件和目录时,很简单 $sudo rm -rf ./* 这没什么,但是,但是如果不小心打成这样 $sudo r ...

  7. LeetCode22 Generate Parentheses

    题意: iven n pairs of parentheses, write a function to generate all combinations of well-formed parent ...

  8. A*算法解决八数码问题 Java语言实现

    0X00 定义 首先要明确一下什么是A*算法和八数码问题? A*(A-Star)算法是一种静态路网中求解最短路径最有效的直接搜索方法也是一种启发性的算法,也是解决许多搜索问题的有效算法.算法中的距离估 ...

  9. create feature from text file

    '''---------------------------------------------------------------------------------- Tool Name: Cre ...

  10. 【开源项目11】组件间通信利器EventBus

    概述及基本概念 **EventBus**是一个Android端优化的publish/subscribe消息总线,简化了应用程序内各组件间.组件与后台线程间 的通信.比如请求网络,等网络返回时通过Han ...