spring boot 读取配置文件的方法

1 将属性写到主配置文件中applacation.properties

直接使用使用@Value注解(spring提供的spel语法)

@Value("${image.localDir}")
   private String localdir;

2 单独写配置文件(例如:image.properties)

1>先扫描到读取配置文件

  @PropertySource(value ="classpath:/image.properties",encoding="UTF-8")
   

2> 读取配置文件中的值

@Value("${image.localDir}")
   private String localdir;
posted @ 2020-09-02 09:37  岁月染过的梦  阅读(273)  评论(0)    收藏  举报