spring boot 读取配置文件信息

1.读取application.properties

@Component
@ConfigurationProperties(prefix="images.product.column")
public class ColumnImageConfig {
    private String path;

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
    
}

使用:在需要的地方 注入该文件,@Autowired xxxConfig  xxx;  调用xxx.getXxx()方法即可

 

不同运行环境使用不同配置文件:

在application.properties中添加

spring.profiles.active = dev  #指定dev为默认配置文件
添加以下配置文件
  • application-dev.properties :开发环境
  • application-test.properties :测试环境
  • application-prod.properties :生产环境

启动时可以使用命令切换使用指定的配置文件:Java -jar myapp.jar --spring.profiles.active = test ,如果没指定,则是应用application.properties中指定的默认配置文件

 

posted @ 2016-06-04 12:17  until-u  阅读(523)  评论(0编辑  收藏  举报