public class ProplUtil {
private static Logger logger = LoggerFactory.getLogger(ProplUtil.class);
private static Properties properties;
static {
InputStream in = null;
try {
properties = new Properties();
in = ProplUtil.class.getResourceAsStream("/application.properties");
properties.load(in);
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getProp(String key){
return properties.getProperty(key);
}
public static Properties getConfig(String name){
Properties props=null;
try{
props = new Properties();
InputStream in = ProplUtil.class.getClassLoader().getResourceAsStream(name);
BufferedReader bf = new BufferedReader(new InputStreamReader(in));
props.load(bf);
in.close();
}catch(Exception ex){
ex.printStackTrace();
}
return props;
}
public static String getPropValue(Properties prop,String key){
if(key == null || "".equals(key.trim())){
return null;
}
String value = prop.getProperty(key);
if(value == null){
return null;
}
value = value.trim();
if(value.startsWith("${") && value.endsWith("}") && value.contains(":")){
int indexOfColon = value.indexOf(":");
String envName = value.substring(2,indexOfColon);
String envValue = System.getenv(envName);
if(envValue == null){
return value.substring(indexOfColon+1,value.length()-1);
}
return envValue;
}
return value;
}
public static void main(String[] args) {
Properties prop = ProplUtil.getConfig("application-"+ProplUtil.getProp("spring.profiles.active")+".properties");
System.out.println( ProplUtil.getPropValue( prop , "receive" ) );
}
}
public String getValue(String key){
Properties prop = new Properties();
try {
InputStream inputStream = this.getClass().getResourceAsStream("/application.properties");
prop.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
return prop.getProperty(key);
}
```java
@Autowired
private Environment env;
String someThing = env.getProperty("file.something");
file.something=D:/SPTFILLS