如何从应用程序读取值.在春季启动时控制器通知文件中的属性



我试图访问RestControllerAdvice文件中application.properties的值。我猜,当通知bean首先加载时,值没有被读取。是否有办法将application.properties文件中的值带入建议文件。

@Value注释从advice控制器中的application.properties读取null

试试

例如:

应用程序。属性文件:

expired.time=1440

在任何文件中,导入:

import org.springframework.beans.factory.annotation.Value;
...
public class AnyClass {
@Value("${expired.time}")
private Integer expiredTime;
}

最新更新