import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication app = new SpringApplication(App.class); ConfigurableApplicationContext context = app.run(args); System.out.println(context.getEnvironment().getProperty("jdbc.pwd")); 9 context.close(); } } apllication.yml 放置在classpath路径下1 jdbc:2 pwd: 123456 #冒号和数字之间有一个空格,没有否则获取失败,pwd前面有缩进两个字符 ps:版本spring-4.3.2-release,springboot-1.4