指定配置文件为属性赋值
需求: YML配置文件是SpringBoot整合第三方配置文件,如果将业务配置与YML配置写到一起,则不方便管理.能否在指定的配置文件(pro)中实现属性的赋值.
@RestController
//导入配置文件,之后由Spring容器扫描
@PropertySource(value = “classpath:/properties/image.properties”, encoding = “UTF-8”)
public class FileController {
@Value("${image.localDir}") //spel表达式Spring框架所提供的.
private String localDir; // = "D:\\JT-SOFT\\images"; //如果放到这里则代码的耦合性高.
@RequestMapping("/getPath")
public String getPath(){
System.out.println("指定图片地址:"+localDir);
return "图片地址为:"+localDir;
}
}