Obtain profile values getProperyValue

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.env.Environment;


public class NPropertyUtil /*extends PropertyPlaceholderConfigurer*/{

    private static Log logger = LogFactory.getLog(NPropertyUtil.class);

    private static Environment env;

    public NPropertyUtil(Environment env) {
        NPropertyUtil.env = env;
    }

    public static String getProperyValue(String key) {
        String value = null;
        if (StringUtils.isNotBlank(key)) {
            value = env.getProperty(key);
            if (StringUtils.isNotBlank(value)) {
                try {
                    value = new String(value.getBytes("ISO-8859-1"), "UTF-8");
                } catch (Exception e) {
                    logger.error("NPropertyUtil Exception", e);
                }
            }
        }
        return value;
    }
 

He published 198 original articles · won praise 23 · Views 100,000 +

Guess you like

Origin blog.csdn.net/stone_tomcate/article/details/100122610