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