Skip to main content


Github | Maven Repository

Getting Started With the Java SDK

Install the latest version


Initialize the client

final PrefabCloudClient prefabCloudClient = new PrefabCloudClient(new Options());


Options options = new Options()
.setPrefabDatasource(Options.Datasources.ALL) // Option: Datasources.LOCAL_ONLY
.setOnInitializationFailure(Options.OnInitializationFailure.) // Option Options.OnInitializationFailure.UNLOCK

Get FeatureFlag

FeatureFlagClient featureFlagClient = prefabCloudClient.featureFlagClient();

.put("group", "beta")

Get Config

final Optional<Prefab.ConfigValue> configValue = prefabCloudClient.configClient().get("the.key");

Typical Usage

We recommend using the PrefabCloudClient as a singleton in your application. This is the most common way to use the SDK.

We have runnable example apps walking through installation, configuration and usage for these containers:

An example of usage in Spring Boot is on the way. Let us know about any others you'd like to see

// Micronaut Factory
public class PrefabFactory {

public PrefabCloudClient prefabCloudClient() {
PrefabCloudClient.Options builder = new PrefabCloudClient.Options();
return new PrefabCloudClient(builder);

public FeatureFlagClient featureFlagClient(
PrefabCloudClient prefabCloudClient
) {
return prefabCloudClient.featureFlagClient();

public ConfigClient configClient(PrefabCloudClient prefabCloudClient) {
return prefabCloudClient.configClient();

public class MyClass {
private ConfigClient configClient;

public String test(String key){
Optional<Prefab.ConfigValue> val = configClient.get(key);
return "Live value of %s is %s".formatted(key, val.orElse("no value found"));

Live Values

Live values are a convenient and clear way to use configuration throughout your system. Inject a prefab client and get live values for the configuration keys you need.

In code, .get() will return the value. These values will update automatically when the configuration is updated in Prefab Cloud.

Get a live value

# .prefab.config.default.yaml
long: 123
string: "hello"
import java.util.function.Supplier;

class MyClass {

private Supplier<String> sampleString;
private Supplier<Long> sampleLong;

public MyClass(ConfigClient configClient) {
this.sampleString = configClient.liveString("sample.string");
this.sampleLong = configClient.liveLong("sample.long");

public String test(){
return "I got %s and %d from Prefab Cloud.".formatted(sampleString.get(), sampleLong.get());


Prefab suggests testing with generous usage of Mockito. We also provide a useful FixedValue for testing Live Values.

void testPrefab(){
ConfigClient mockConfigClient = mock(ConfigClient.class);
when(mockConfigClient.liveString("sample.string")).thenReturn(FixedValue.of("test value"));

MyClass myClass = new MyClass(mock(ConfigClient.class));

// test business logic