读取properties的简单方法,使用@Configuration
- 配置类代码如下
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; @Configuration
public class Config {
@Value("${test}")
private String test; public String getTest() {
return test;
} }
2.Spring配置
<!-- 获取配置属性值 -->
<bean id="configProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:app/env/config.properties</value>
<value>classpath:app/config/database.properties</value>
<value>classpath:app/config/redis.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties" />
</bean>
3.测试接口类
@Service
public class SsoInterface { @Autowired
private SsoConfig SsoConfig; public void test(){
System.out.println(SsoConfig.getTest());
} }
最后就能输出 需要的配置文件对应信息
读取properties的简单方法,使用@Configuration的更多相关文章
- java读取properties配置文件的方法
app.properties mail.smtp.host=smtp.163.com mail.transport.protocol=smtp import java.io.InputStream; ...
- java读取Properties文件的方法
resource.properties的内容: com.tsinkai.ettp.name=imooc com.tsinkai.ettp.website=www.imooc.com com.tsink ...
- 读取properties配置文件的方法
一般在.properties文件中配置数据库连接的相关信息,我们需要从中读取信息,以便建立与数据库的连接. 文件目录: application.properties配置信息: url=jdbc:ora ...
- 读取Properties文件六种方法
1.使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream ...
- JS读取.properties文件的方法
假设有JavaScript文件叫做:readproperties.js,这个文件需要读取config.properties这个配置文件,步骤如下: 1. 下载插件jquery.i18n.proper ...
- 在JavaScript文件中读取properties文件的方法
假设有JavaScript文件叫做:readproperties.js,这个文件需要读取config.properties这个配置文件,步骤如下: 1. 下载插件jquery.i18n.proper ...
- Java项目中读取properties文件,以及六种获取路径的方法
下面1-4的内容是网上收集的相关知识,总结来说,就是如下几个知识点: 最常用读取properties文件的方法 InputStream in = getClass().getResourceAsStr ...
- 用eclipse做项目中常遇到的问题-如何创建并读取properties文件
在用eclipse做项目开发的时候我们常常会将一些重要的内容写在配置文件里面, 特别是连接数据库的url,username,password等信息,我们常常会新建一个properties文件将所有信息 ...
- java读取properties配置文件信息
一.Java Properties类 Java中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件,各种语言都有自己所支持的配置文件,配置 ...
随机推荐
- 在邮箱服务器上执行Powershell命令Get-MessageTrackingLog 报错
开启对应的服务即可. 中文环境: 英文环境:
- 2017 ACM/ICPC Asia Regional Shenyang Online transaction transaction transaction
Problem Description Kelukin is a businessman. Every day, he travels around cities to do some busines ...
- 安装pywin32出现--Python version 3.x required, which was not found in the registry
这两天安装pywin32时出现了这个问题 双击.exe文件进入安装界面,然后点击下一步,它会自动定位你的python安装在什么地方,但是我的安装过程中未自动定位到python安装位置,并显示显示: 安 ...
- python3——“->”的含义
->:标记返回函数注释,信息作为.__annotations__属性提供,__annotations__属性是字典.键return是用于在箭头后检索值的键.但是在Python中3.5,PEP 4 ...
- Spring Boot 整合 Hibernate5
Run java -jar -Dspring.profiles.active=dev sport.web.services.jar Maven <parent> <groupId&g ...
- Zookeeper问题汇总
1. 遗留问题 a). zookeeper集群如何保证请求的均匀分布? 2. ZK概念澄清 2.1 ZK节点类型 CreateMode.PERSISTENT //持久节点,该节点客户端断开后不会删除 ...
- htaccess转换httpd.ini方法及案例参考
案例1:httpd.ini适合IIS使用,.htaccess适合Apache使用,nginx.conf适合Nginx使用 转换前:httpd.ini [ISAPI_Rewrite] # 3600 = ...
- android 开发-数据存储之文件存储
android的文件存储是通过android的文件系统对数据进行临时的保存操作,并不是持久化数据,例如网络上下载某些图片.音频.视频文件等.如缓存文件将会在清理应用缓存的时候被清除,或者是应用卸载的时 ...
- win8.1x64下完美运行IE6
IE6我相信是所有前端人员永远都绕不过去的坎,操作的版本越来越高,离xp越来越远,难道你还在win8下安装个虚拟机来运行IE6吗?这样即消耗系统资源,来回的切换也麻烦,关键是只为了一个测试哦,没必要这 ...
- 使用jQuery实现文本框input定位到文字最后(兼容所有浏览器)
$.fn.setCursorPosition = function(position){ if(this.lengh == 0) return this; return $(this).setSele ...