image.png

资源文件:file-upload-dev.properties

  1. file.imageUserFaceLocation=D:\\Environment\\apache-tomcat-9.0.46\\webapps\\foodie\\faces

类映射

  1. package com.shiers.resource;
  2. import org.springframework.boot.context.properties.ConfigurationProperties;
  3. import org.springframework.context.annotation.PropertySource;
  4. import org.springframework.stereotype.Component;
  5. /**
  6. * Demo class
  7. *
  8. * @author shierS
  9. * @date 2021/6/6
  10. */
  11. @Component //组件标识,被spring扫描
  12. @ConfigurationProperties(prefix = "file") //读取配置文件 prefix 指定属性的前缀
  13. @PropertySource("classpath:file-upload-dev.properties") //配置对应配置文件的地址
  14. public class FileUpload {
  15. private String imageUserFaceLocation;
  16. public String getImageUserFaceLocation() {
  17. return imageUserFaceLocation;
  18. }
  19. public void setImageUserFaceLocation(String imageUserFaceLocation) {
  20. this.imageUserFaceLocation = imageUserFaceLocation;
  21. }
  22. }

使用

  1. @Autowired
  2. private FileUpload fileUpload;
  3. String fileSpace = fileUpload.getImageUserFaceLocation();