public class ServiceUtil {
private static Properties readPropertiesFile(String fileName) {
try {
Resource resource = new ClassPathResource(fileName);
Properties props = PropertiesLoaderUtils.loadProperties(resource);
return props;
} catch (Exception e) {
logger.error("readPropertiesFile error, fileName:{}", fileName, e);
}
return null;
}
@PostConstruct
void init(){
try{
Properties properties = readPropertiesFile("application.properties");
String env = properties.getProperty("spring.profiles.active");
System.out.println("env: " + env);
}catch (Exception e){
logger.error("get env error", e);
}
}
public static void main(String[] args) {
Properties properties = readPropertiesFile("application.properties");
System.out.println(properties.getProperty("spring.profiles.active"));
}
}