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