zoukankan      html  css  js  c++  java
  • spring项目读取配置文件

    Spring项目在运用中读取配置文件有两种方式:

    通过项目的配置文件读取

    在spring-context.xml里面加入以下代码

    在运用到的类里面加入

        @Value("#{configProperties['staticUrl']}")
    private String staticUrl;
    

    通过代码读取配置文件

    获取的代码

    public class ConfigurationUtil {
    
    
    
    	/**
    	 * 获取
    	 * 
    	 *@param pathUrl 路径     文件所在的路径,前后都不需要加"/"
    	 *@param fileName 文件名称      前面不需要加"/"
    	 *
    	 *@return Properties对象
    	 */
    	public static Properties get(String pathUrl, String fileName) {
    		Properties prop = new Properties();
    		String path = Thread.currentThread().getContextClassLoader().getResource("/" + pathUrl).getPath();
    		try {
    			InputStream is = new FileInputStream(path + "/" + fileName);
    			prop.load(is);
    		} catch (Exception e) {
    
    		}
    		return prop;
    	}
    }
    

    需要引用的地方

  • 相关阅读:
    通道分离与合并
    opencv颜色表操作
    opencv trackbar
    像素操作
    opencv 像素读写
    py 时间与日期
    py 字典
    py 元组
    py 列表
    课后作业-阅读任务-阅读提问-3
  • 原文地址:https://www.cnblogs.com/nikeodong/p/8183166.html
Copyright © 2011-2022 走看看