spring通过静态方法获得properties文件的值
获得spring bean方法
@Component
public class BeanUtils implements ApplicationContextAware { private static ApplicationContext applicationContext; @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
} public static ApplicationContext getApplicationContext() {
return applicationContext;
} public static <T> T getBean(Class<T> clazz) throws BeansException {
return applicationContext.getBean(clazz);
} public static Object getBean(String name) throws BeansException {
return applicationContext.getBean(name);
} }
使用value注解注入properties文件中的属性,提供静态访问
@Component
public class Constant { @Value("${server}")
private String server; public static Constant bean() {
return BeanUtils.getBean(Constant.class);
} public String getServer(){
return server;
}
}
在其它类中就可以使用 Constant.bean().getServer()来获得server属性的值了
spring通过静态方法获得properties文件的值的更多相关文章
- Spring 通过配置文件注入 properties文件
当我们需要将某些值放入 properties文件 key=value 的方式,获取文件信息使用spring 注入的方式会变得很便捷 1. spring 配置文件需要导入 <?xml versio ...
- Spring 配置文件中将common.properties文件外置
将配置文件的路径从项目中移出来 1. 在springApplicationContext中 <context:property-placeholder location="file:$ ...
- 161216、使用spring的DefaultResourceLoader自定义properties文件加载工具类
import java.io.IOException; import java.io.InputStream; import java.util.NoSuchElementException; imp ...
- spring注解中使用properties文件
一.只读取单个 properties 文件 1.在 spring 的配置文件中,加入 引入命名空间: xmlns:util="http://www.springframework.org/s ...
- 解密Spring加载的Properties文件
Spring的框架中,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer类可以将.properties(key ...
- 在Spring环境下存取properties文件…
Spring中PropertyPlaceholderConfigurer的使用 (1) 基本的使用方法是 classpath:/spring/include/dbQuery.properties 其中 ...
- 使用spring的DefaultResourceLoader自定义properties文件加载工具类
转自:https://www.cnblogs.com/zrbfree/p/6230957.html import java.io.IOException; import java.io.InputSt ...
- JdbcTemplae使用入门&&Spring三种连接池配置&&Spring配置文件引用外部properties文件
JdbcTemplate的使用 Spring为了各种支持的持久化技术,都提供了简单操作的模版和回调. JdbcTemplate 简化 JDBC 操作HibernateTemplate 简化 Hiber ...
- spring配置中,properties文件以及xml文件配置问题
spring方便我们的项目快速搭建,功能强大,自然也会是体系复杂! 这里说下配置文件properties管理的问题. 一些不涉及到代码逻辑,仅仅只是配置数据,可以放在xxxx.properties文件 ...
随机推荐
- 去繁从简--简化Message和Signal设置
以往的版本中如果添加了消息或者信号类型的事件需要先在流程属性(设置流程ID的界面)中添加Message和Signal,之后再选择对应的事件在属性中的下拉框中选择已经定义的Message或Signal. ...
- MongoDB 概念解析
SQL术语/概念 MongoDB术语/概念 解释/说明 database database 数据库 table collection 数据库表/集合 row document 数据记录行/文档 col ...
- Android开发之Git配置
Android开发之Git配置 1.首先git配置: 输入命令: git config --global user.name "xxx.xx" git config --globa ...
- [分享] 史上最简单的封装教程,五分钟学会封装系统(以封装Windows 7为例)
[分享] 史上最简单的封装教程,五分钟学会封装系统(以封装Windows 7为例) 踏雁寻花 发表于 2015-8-23 23:31:28 https://www.itsk.com/thread-35 ...
- hub config
@echo off title Selenium_Hub cd /d %~dp0 java -jar selenium-server-standalone-2.48.2.jar -role hub - ...
- 整合TabBarController与NavigationController
一.项目结构 一开始创建一个空的项目
- Centos6.5下的Hadoop安装
开始进行云计算部分的学习,为了存档,写下现在进行过的步骤 需要用到的主要版本: 虚拟机:Vmware Workstation pro 12.5 Linux系统:CentOS6.4 64bit jdk版 ...
- SPSS中两种重复测量资料分析过程的比较
在SPSS中,有两个过程可以对重复测量资料进行分析:一种是一般线性模型的重复度量:一种是混合线性模型,对于同样的数据资料,使用两种过程分析出的内容不大一样,注意是内容而不是结果,只要操作正确,结果应该 ...
- 1028作业:Java语法基础
//1.输入长与宽计算长方形面积与周长.(用精度类型计算) package com.lovo.J133; import java.util.Scanner; public class Homework ...
- flume安装及配置介绍(二)
注: 环境: skylin-linux Flume的下载方式: wget http://www.apache.org/dyn/closer.lua/flume/1.6.0/apache-flume-1 ...