java spring boot 读取 application.properties

import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

import java.io.IOException;
import java.util.Properties;

public class ApplicationHelper {

    public static String getPropertyValue(String key) throws IOException {
        ResourceLoader resourceLoader = new DefaultResourceLoader();
        Resource resource = resourceLoader.getResource("application.properties");
        Properties properties = new Properties();
        properties.load(resource.getInputStream());
        return properties.getProperty(key);
    }
}

 

posted on 2022-05-11 15:45  空明流光  阅读(200)  评论(0编辑  收藏  举报

导航