SpringBoot读取指定配置文件

114 阅读1分钟
image.png

通过@PropertySource注解读取指定配置文件

@RestController
@RequestMapping
@PropertySource(value = "classpath:{exception.properties}", encoding = "UTF-8")
public class TestPropertiesController {
    @Autowired
    Environment env;

    @GetMapping("testEnv")
    public String testENV(HttpServletRequest request) {
        return env.getProperty("DEMO_00001");
    }
}