在resources下创建配置文件,如constant.properties
,properties文件以key-value的形式表示
base-path=/home/data/
version=1.0.0
在类中,通过@PropertySource
来指定配置文件,@Value
来取值
@RestController
@RequestMapping(value = "/test")
// 引入配置文件
@PropertySource(value = "classpath:config/constant.properties")
public class TestController {
// 取值
@Value("${base-path}")
private String basePath;
@GetMapping
public void test() {
System.out.println(basePath);
}
}