java 配置文件读取方法

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Component
//配置文件名称
@PropertySource("classpath:propertyConf.yml")
//配置文件数据
@ConfigurationProperties(prefix = "message")
public class MessageIpConf {
    @Value("${accessToken}")
    private String accessToken;
}
//配置文件数据规则
message:
  accessToken: xxxxxxxxxxxxxxxxx

你可能感兴趣的:(java 配置文件读取方法)