用 @Value("${xxxx}")注解从配置文件读取值的用法
2024-10-19 14:58:49
1. 用法:
从配置properties文件中读取init.password 的值。
@Value("${init.password}")
private String initPwd;
2. 在spring的配置文件中加载配置文件dbconfig.properties :
<!-- 加载配置文件 -->
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="fileEncoding" value="UTF-8"/>
<property name="locations">
<list>
<value>classpath:dbconfig.properties</value>
</list>
</property>
</bean>
或者这样加载:
<context:property-placeholder location="classpath:dbconfig.properties" />
或者这样加载:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="location">
<value>dbconfig.properties</value>
</property>
</bean>
3. dbconfig.properties 文件:
#MD5
password.algorithmName=md5
password.hashIterations=2
#initpwd
init.password=admin
最新文章
- python学习之day4,函数
- Visual Studio 2012 常用快捷键
- 问:Linux下Chrome标题栏中文乱码
- Git 基础应用
- POJ -3190 Stall Reservations (贪心+优先队列)
- const 的全面总结
- 关于java环境配置的问题
- JAVA学习-JAVA环境准备
- java socket报文通信(一)socket的建立
- js中几个容易混淆的概念
- Asp.Net MVC3 简单入门第一季(三)详解Controller之Filter
- SAE上使用本地sql文件建表时出错解决方法
- hdu2534-Score
- a标签点击之后有个虚线边框,怎么去掉
- Redis 2种持久化模式的缺陷
- Python中的可视化神器:pyecharts
- django rest framework批量上传图片及导入字段
- 十九、Linux 进程与信号---环境表
- 【linux轻松学】centos6.5上搭建svn服务器
- golang map输出排序
热门文章
- VMware虚拟机 + ubuntu16.04 Linux OpenCV打不开摄像头解决办法
- Vulnhub靶机渗透 -- DC5
- redis 主从复制详解
- VUE006. 前端跨域代理服务器ProxyTable概述与配置
- Weblogic漏洞分析之JNDI注入-CVE-2020-14645
- xxl-job <;=2.0.2 反序列化漏洞
- Ubuntu中类似QQ截图的截图工具并实现鼠标右键菜单截图
- Apache设置禁止访问网站目录
- Jmeter系列(15)- 常用断言之大小断言
- markdown写作系统