public class PropertiesUtil { private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class); private static final String file_name = "xxl-job-admin.properties"; public static String getString(String key) { Properties prop = null; try { Resource resource = new ClassPathResource(file_name); EncodedResource encodedResource = new EncodedResource(resource,"UTF-8"); prop = PropertiesLoaderUtils.loadProperties(encodedResource); } catch (IOException e) { logger.error(e.getMessage(), e); } if (prop!=null) { return prop.getProperty(key); } return null; } public static void main(String[] args) { System.out.println(getString("xxl.job.login.username")); } }
获取classpath配置文件工具类
最新推荐文章于 2021-02-27 06:51:30 发布