Spring Boot通过@PropertySource注解来加载配置文件。
@SpringBootApplication注解所在的类上添加@PropertySource注解,指定要加载的配置文件路径。例如,加载名为application.properties的配置文件,代码如下:@SpringBootApplication@PropertySource("classpath:application.properties")public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); }}在application.properties配置文件中,添加需要的配置项。例如:server.port=8080在需要获取配置项的地方,使用@Value注解来注入配置项的值。例如,在一个@Component标注的类中获取server.port配置项的值:@Componentpublic class MyComponent { @Value("${server.port}") private String port; // ...}以上就是使用Spring Boot加载配置文件的方法。在配置文件中添加需要的配置项,并在需要使用的地方通过注解来获取配置项的值。

