Spring 通过配置文件注入 properties文件
当我们需要将某些值放入 properties文件 key=value 的方式,获取文件信息使用spring 注入的方式会变得很便捷
1. spring 配置文件需要导入
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns:util="http://www.springframework.org/schema/util"
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd">
2.配置文件路径
<util:properties id="exception" location="classpath:config/exceptiontype.properties"/>
3.在使用的类添加属性注入
@Component
public class ExceptionConverter extends AbstractExceptionInterceptor { @Value("#{exception}")
private Properties expt;
public void setKey(){
String code=expt.getProperty("这里是Properties文件的key");
}
}
好啦,做个笔记!!!
好记性不如烂笔头
Spring 通过配置文件注入 properties文件的更多相关文章
- 谈谈Spring 注入properties文件总结
本篇谈谈Spring 注入properties文件总结,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧 spring提供了多种方式来注入properties文件,本文做一个 ...
- spring boot 在框架中注入properties文件里的值(Spring三)
前一篇博客实现了打开第一个页面 链接:https://blog.csdn.net/qq_38175040/article/details/105709758 本篇博客实现在框架中注入propertie ...
- spring通过静态方法获得properties文件的值
获得spring bean方法 @Component public class BeanUtils implements ApplicationContextAware { private stati ...
- log4CXX第二篇---配置文件(properties文件)详解
一.Log4j简介 Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使 ...
- Spring自动注入properties文件
实现spring 自动注入属性文件中的key-value. 1.在applicationContext.xml配置文件中,引入<util />命名空间. xmlns:util=" ...
- Spring/Maven/MyBatis配置文件结合properties文件使用
使用properties文件也叫注入,比如把一些常用的配置项写入到这个文件,然后在Spring的XML配置文件中使用EL表达式去获取. 这种方式不只Spring可以使用,同样MyBatis也可以使用, ...
- spring配置文件引入properties文件:<context:property-placeholder>标签使用总结
一.问题描述: 1.有些参数在某些阶段中是常量,比如: (1)在开发阶段我们连接数据库时的连接url.username.password.driverClass等 (2)分布式应用中client端访问 ...
- spring注解中使用properties文件
一.只读取单个 properties 文件 1.在 spring 的配置文件中,加入 引入命名空间: xmlns:util="http://www.springframework.org/s ...
- 在Spring环境下存取properties文件…
Spring中PropertyPlaceholderConfigurer的使用 (1) 基本的使用方法是 classpath:/spring/include/dbQuery.properties 其中 ...
随机推荐
- shell,bash,git bash,xshell,ssh
一:shell是linux/unix系统的外壳,也可以理解为命令行接口,就是你输入并执行命令行的地方.bash(born again shell)是shell的一种,最常用的shell之一.你在你的l ...
- BW顾问必需要清楚的:时间相关数据建模场景需求分析
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- RSA5、RSA6
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 自己常用JS和JQ 函数
//验证码函数 <button id="send">点击发送验证码</button> <script src="jquery.min.js& ...
- 《与小卡特一起学Python》 Code6 注释
"""这是一个包括多行的注释, 使用了三重引号字符串. 这不完全是注释,不过也可以相当于注释. """ #***************** ...
- javascript的继承小结
继承是OO语言中最为津津乐道的概念,一般有两种继承方式,接口继承和实现继承,接口继承只继承方法签名,实现继承则是集成真正的方法.由于js中函数没有签名,因此ECMAScript中没有接口继承,只有实现 ...
- php 判断当前的操作系统的方法
因为windows 和 linux 下的标识符是不一样的,所以写了个方法来获取当前的标识符. /** * 对操作系统进行判断 * @return string */ static function j ...
- Nginx基础知识之————RTMP模块中的中HLS专题(翻译文档)
一.在Nginx配置文件的RTMP模块中配置hls hls_key_path /tmp/hlskeys; 提示错误信息: nginx: [emerg] the same path name " ...
- eclipse rcp 打包出适合不同操作系统和操作位数.
http://blog.csdn.net/luoww1/article/details/8677999 http://blog.csdn.net/soszou/article/details/8053 ...
- Java之工厂方法
普通工厂模式: 第一步:定义接口,坚持面向接口编程, package dp; public interface Sender { public void send();} 第二步:实现接口: p ...