【发布时间】:2020-07-09 16:26:17
【问题描述】:
我有一个常量类,其中所有常量都已定义。常量的值位于我的自定义属性文件中,而属性文件位于包中。我正在尝试使用我的常量类读取自定义属性文件中的值。
我的常量类
package com.example.demo.properties
public interface AppConstant {
//my custom constants
String REQUEST_SUCCESS = "REQUEST_SUCCESS";
String INTERNAL_ERROR = "INTERNAL_ERROR";
String REQUEST_FAIL = "REQUEST_FAIL";
}
AppProps.properties
//values for constants in properties file
//package com.example.demo.properties
REQUEST_SUCCESS = Request was successful
INTERNAL_ERROR = Internal Error
REQUEST_FAIL = Request Failed due to error
我正在尝试使用 java.util.Properties 读取属性文件。有人可以告诉我如何使用 Spring Boot 注释读取该值。
【问题讨论】:
-
Spring boot也有@value注解, -
@emotionlessbananas
@Value应该在常量类中使用吗? -
恕我直言,常量接口非常老派。为什么需要它。
标签: java spring spring-boot