必威体育Betway必威体育官网
当前位置:首页 > IT技术

获取YML文件中的值

时间:2019-10-06 12:13:23来源:IT技术作者:seo实验室小编阅读:81次「手机版」
 

yml

yml文件

web:
  uploadPath: ${web.upload_path}
  platformUrl: ${web.platform_url}

代码中通过@Value使用yml中给的值

@Value("${web.uploadPath}")
private String uploadpath;

 

因为yml文件不能通过@VALUE获取,启动项目会报错

org.Springframework.beans.factory.BeanCreationException: ERROR creating bean with name 'yssCoursePortalcontroller': Injection of autowired dependencies failed; nested exception is java.lang.illegalargumentException: Could not resolve placeholder 'web.uploadpath' in string value "${web.uploadpath}"

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'web.uploadpath' in string value "${web.uploadpath}"

使用实体类

package com.xinlianpu.village.utils;


import org.springframework.boot.context.properties.configurationProperties;
import org.springframework.stereotype.component;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


@Component
@ConfigurationProperties(prefix = "web")
public class YmlValueUtil {
    private String uploadPath;
    private String platformUrl;

    private final Security security = new Security();

    public String getUploadPath() {
        return uploadPath;
    }

    public void setUploadPath(String uploadPath) {
        this.uploadPath = uploadPath;
    }

    public String getPlatformUrl() {
        return platformUrl;
    }

    public void setPlatformUrl(String platformUrl) {
        this.platformUrl = platformUrl;
    }

    public Security getSecurity() {
        return security;
    }

    public static class Security{
        private String userName;
        private List<String> roles = new ArrayList<>(Collections.singleton("USER"));
        public String getUserName() {
            return userName;
        }
        public void setUserName(String userName) {
            this.userName = userName;
        }
        public List<String> getRoles() {
            return roles;
        }
        public void setRoles(List<String> roles) {
            this.roles = roles;
        }
    }
}

在其它文件中使用

注入

@Autowired
private YmlValueUtil ymlValueUtil;

获取使用

File file = new File(ymlValueUtil.getUploadPath() +  "/course" + course.getId() + ".html");

相关阅读

M3U文件制作与视频播放器播放M3U

M3U本质上说不是音频文件,它是音频文件的列表文件,是纯文本文件。你下载下来打开它,播放软件并不是播放它,而是根据它的记录找到网络

【JS】获取当前时间,且格式为yyyy-MM-dd hh:mm:ss

我们在前端获取当前时间:var nowDate = new Date();时间格式为:Sun May 27 2018 19:28:09 GMT+0800 (中国标准时间)但是我们想在页

CSV文件的创建与读取

一 CSV文件 CSV文件是最常用的一个文件存储方式。逗号分隔值(Common-Separated Values,CSV)文件以纯文本形式存储表格数据(注:分隔字

免费获取华夏邓白氏编码(021-26107504)

1、在苹果网站登录你的apple id账户2、访问这个网站https://developer.apple.com/enroll/duns-lookup/#/search  (要确定贵公司是

使用Python获取磁力种子

一、磁力链接 现在我们使用迅雷等工具下载资源的时候,基本上都只需要一个叫做磁力链接的东西就可以了,非常方便。 二、磁力定义 磁

分享到:

栏目导航

推荐阅读

热门阅读