ConfigUtil.java 888 B

12345678910111213141516171819202122232425262728293031
  1. package com.tzld.piaoquan.longarticle.utils;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.springframework.core.io.ClassPathResource;
  4. import java.io.IOException;
  5. import java.util.Properties;
  6. @Slf4j
  7. public class ConfigUtil {
  8. private static Properties properties = readProperties("application.properties");
  9. private static Properties readProperties(String... confFile) {
  10. final Properties properties = new Properties();
  11. try {
  12. for (String path : confFile) {
  13. final ClassPathResource resource = new ClassPathResource(path);
  14. properties.load(resource.getInputStream());
  15. }
  16. } catch (IOException e) {
  17. log.error("ConfigUtil readProperties error", e);
  18. }
  19. return properties;
  20. }
  21. public static String getConfig(String key) {
  22. return properties.getProperty(key);
  23. }
  24. }