需要两步骤
1、在类上添加注解@PropertySource,指定配置文件路径,默认路径下可以不添加此注解(application.properties中的配置信息读取就不需要此注解,直接第二步)
classpath:con/myConfig.properties指的是src/main/resources目录下con目录下的myConfig.properties文件
@PropertySource({"classpath:config/my.properties","classpath:config/config.properties"})
public class TestController
2、在属性名上添加@Value注解
@Value("${file.name}")
private String fileName;
Spring注解配置详解
本文详细介绍了如何在Spring框架中使用@PropertySource和@Value注解进行外部配置文件的加载和属性值注入,通过示例展示了注解的具体应用。
2359

被折叠的 条评论
为什么被折叠?



