需要两步骤
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;