Java获取application.properties配置参数

import 对应的 package

import java.util.Properties;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

//从application.properties文件中获取用到的参数;
Resource resource = new ClassPathResource("application.properties");
Properties props = PropertiesLoaderUtils.loadProperties(resource);
String host = props.getProperty("mail.host");
int port = Integer.parseInt(props.getProperty("mail.port")); 

转载:https://blog.csdn.net/wk1063645973/article/details/98880901

posted @ 2020-03-12 10:41  ___mouM  阅读(2090)  评论(0编辑  收藏  举报