之前看的文章都说需要RestController或Service才能得到值,经测试这种方式,普通Controller也可以得到,代码如下。
@Controller @Configuration @PropertySource("classpath:application.properties") public class NormalController { @Autowired private Environment env; private void aMethod(){ String val = env.getProperty("file_path"); } }