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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM