首页 > 编程语言 > 详细

springboot--读取配置文件

时间:2019-06-17 11:13:50      阅读:128      评论:0      收藏:0      [点我收藏+]
config.name=configname
config.password=configpassword
@Configuration
@ConfigurationProperties(prefix = "config")
@PropertySource("classpath:/config.properties")
public class Config {
    private String name;

    private String password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

 @EnableConfigurationProperties({Config.class})  
使用的时候直接注入即可
@Autowired
Config config;

 

 

@ComponentScans({@ComponentScan("com.dx.controller"), @ComponentScan("app.config")})

springboot--读取配置文件

原文:https://www.cnblogs.com/jentary/p/11038564.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!