Skip to content

Instantly share code, notes, and snippets.

@j-tim
Last active October 18, 2019 11:57
Show Gist options
  • Save j-tim/01fc7804fd6ad447747f16db2a676b9e to your computer and use it in GitHub Desktop.
Save j-tim/01fc7804fd6ad447747f16db2a676b9e to your computer and use it in GitHub Desktop.
Spring Boot 2.2 Immutable configuration binding class example
package com.example.immutable.configuration.binding;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;
@Getter
@ConfigurationProperties("stock.quote.subscription")
public class ImmutableStockQuoteSubscriptionProperties {
private final String endpoint;
private final String apiKey;
private final SubscriptionType subscriptionType;
private final boolean enabled;
@ConstructorBinding
public ImmutableStockQuoteSubscriptionProperties(String endpoint, String apiKey, SubscriptionType subscriptionType, boolean enabled) {
this.endpoint = endpoint;
this.apiKey = apiKey;
this.subscriptionType = subscriptionType;
this.enabled = enabled;
}
enum SubscriptionType {
/**
* Real time stock quotes
*/
REALTIME,
/**
* Stock quotes that are delayed by 15 minutes
*/
DELAYED,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment