在Spring boot 项目中,我们多使用application.yml 或者application.properties . 如何在项目中使用自定义的 properties 呢,以下示例教你解决。
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Getter
@Component
@PropertySource(value = "classpath:versionInfo.properties")
public class VersionInfo {
@Value("${example.platform}")
private String platform;
@Value("${example.version}")
private String version;
@Value("${example.branch}")
private String branch;
@Value("${example.buildDate}")
private String buildDate;
}