@Value() 使用方法

使用@Value():

1、该注解所在的类,必须要被扫描到:

  <context:component-scan base-package="com.laiw"/>

备注:

  1、在静态类,该注解无效

  2、无效,使用properties进行取值:

  

public static final String GLOBAL_CONFIG_PATH = "file:" + System.getProperty("integral.config.path");


public static String getProperties(String key) {
        try {
            Properties p = PropertiesLoader.loadProperties(GLOBAL_CONFIG_PATH + "/integral.properties");
            return p.getProperty(key);
        } catch (IOException e) {
            logger.error("错误", e, e.getMessage());
        }
        return "";
    }


public static final String HR_VERSION = PropertiesLoader.getProperties("HRVersion");

    public static final String BR_MERCHANT_CODE = PropertiesLoader.getProperties("bankMerchantCode");
工作小总结,有错请指出,谢谢。
原文地址:https://www.cnblogs.com/zilanghuo/p/6655937.html