import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ConfigUtils {
private static Properties configfile = null;
static {
InputStream in = ConfigUtils.class.getClassLoader()
.getResourceAsStream("config.properties");
configfile = new Properties();
try {
configfile.load(in);
in.close();
} catch (IOException e) {
System.out.println("No config.properties defined error");
}finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
in = null;
}
}
}
public String getPropertiesByKey(String _key) {
return configfile.getProperty(_key);
}
}
调用:
//spring mvc注解
@Resource
private ConfigUtils config;
@Override
public void exportExcel() {
config.getPropertiesByKey(“key”)
}