SpringBoot使用一个全局的配置文件,配置文件名是固定的:application.properties、application.yml。
位置:src/main/resources/application.properties
常用配置:
server.port=8888:修改SpringBoot服务端口
当同时配置了application.properties和application.yml时,application.properties的配置会覆盖application.yml中的配置。
chart.line.name=hello
chart.bar.width=2.5
jdbc.url1=jdbc.mysql://127.0.0.1/xxx
a.list=a\
b\
c\
d
! this is a comment
# this is a comment
ConfigurableApplicationContext ctx = SpringApplication.run(ConfigTestApplication.class, args);
System.out.printf("chart.line.name=%s\n", ctx.getEnvironment().getProperty("chart.line.name", String.class));
System.out.printf("chart.bar.width=%f\n", ctx.getEnvironment().getProperty("chart.bar.width", Float.class));
System.out.printf("jdbc.url1=%s\n", ctx.getEnvironment().getProperty("jdbc.url1", String.class));
System.out.printf("a.list=%s\n", ctx.getEnvironment().getProperty("a.list", String.class));