静态配置文件注入,非spring形式


config.properties

# config
target_endpoint=http://111.20.69.104:7018/services/CussyncService?wsdl

注入:

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;

public class ConfigFileReader {
	private static final Logger log = Logger.getLogger(ConfigFileReader.class);
	static Properties p = new Properties();
	static {
		try {
			log.info("*** 读配置文件开始...");
			InputStream ins = ConfigFileReader.class.getClassLoader()
					.getResourceAsStream("config.properties");
			p.load(ins);
			log.info("######################");
			log.info("target_endpoint="+getTargetEndPoint());
			log.info("######################");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static String getTargetEndPoint() {
		return p.getProperty("target_endpoint");
	}
}

猜你喜欢

转载自blog.csdn.net/u011702993/article/details/79400296