核心code如下:

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"));

08-10 13:23