外部属性文件的使用
2017-02-20 14:48
190 查看
可以使用properties文件或yml文件,这里以yml文件为例
application.yml
注意,:冒号与值之间要有一个空格
属性文件注入
引用
application.yml
server:
port: 9090
context-path: /sbapp
local:
name: Zzz
注意,:冒号与值之间要有一个空格
属性文件注入
package com.wisely.bean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
/**
* Created by sherry on 17/2/16.
*/
@Component
@PropertySource("application.yml")
public class ReadYml {
@Bean("port")
public String port(@Value("${server.port}") String port){
return port;
}
@Bean("name")
public String name(@Value("${local.name}") String name){
return name;
}
}
引用
@Autowired
@Qualifier("name")
private String name;
相关文章推荐
- Spring IOC使用外部属性文件
- Spring 使用外部属性文件
- spring中使用外部属性文件(关于PropertyPlaceholderConfigurer)
- Spring4深入理解IOC&DI02----Bean配置--自动装配、bean之间的继承与依赖、使用外部属性文件
- spring 使用外部属性文件
- Spring 中如何使用外部属性文件
- 22Spring_JdbcTemplatem模板工具类的使用——使用外部属性文件来配置(properties)
- Spring基础—— 在 Spring Config 中使用外部属性文件
- Spring使用外部属性文件以及常见错误(内附大量图片,很有借鉴意义)
- spring4学习:使用外部属性文件
- 4、使用外部属性文件
- Spring-Bean配置-使用外部属性文件
- Spring_使用外部属性文件
- 在Spring中如何使用加密外部属性文件
- Spring 使用外部属性文件(连接数据库)
- 【跟我学spring 4.0 】之第七节-spring使用外部属性文件-spring配置连接oracle数据库
- Spring 学习笔记 8. 尚硅谷_佟刚_Spring_使用外部属性文件
- Spring-6 使用外部属性文件
- Spring学习记录(六)---使用外部属性文件