weixin_42467871
akmxl
2019-01-08 23:10

springboot使用spring.profiles.active=local加载配置文件失败?

  • spring

springboot使用spring.profiles.active

springboot项目
有FileConfig配置类,需要读取配置文件的配置,开发环境和测试环境不同,于是想通过改spring.profiles.active属性切换:

配置类代码:

@ConfigurationProperties(prefix = "upload.file")
@Component
public class FileConfig {

    @Value("${maxsize}")
    private String maxsize;
    @Value("${uploadHost}")
    private String uploadHost;
    @Value("${uploadDir}")
    private String uploadDir;

    public String getMaxsize() {
        return maxsize;
    }

    public void setMaxsize(String maxsize) {
        this.maxsize = maxsize;
    }

    public String getUploadHost() {
        return uploadHost;
    }

    public void setUploadHost(String uploadHost) {
        this.uploadHost = uploadHost;
    }

    public String getUploadDir() {
        return uploadDir;
    }

    public void setUploadDir(String uploadDir) {
        this.uploadDir = uploadDir;
    }
}

配置文件代码:
图片说明

打包成jar包前,在application.yml里面配置spring.profiles.active=local,想加载application-local.yml配置文件:配置文件

但启动时,报错:
图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答