spring boot 程序取yml数据

1.实体类获取

@Component
@ConfigurationProperties(prefix = "topic")
@Data
public class PropertiesUtil {

    private String topicName;

    private String groupId;

    private String clientId;

    private String bootstrapServers;

    private String dbType;

    private String serverLoginName;

    private String serverPassword;
}
topic:
  topicName: topicName123
  groupId: groupId123
  clientId: clientId123

2.字段获取

    @Value("${algorithm.url}")
    private String url;
algorithm:
  url: 12345
  filePath: wenjian/dizhi

你可能感兴趣的:(spring,boot,java,数据库)