Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
Created June 5, 2014 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasdarimont/25c2836ffd696026bc17 to your computer and use it in GitHub Desktop.
Save thomasdarimont/25c2836ffd696026bc17 to your computer and use it in GitHub Desktop.
Runtime Spring Configuration
package de.tutorials.training.springconfig;
import java.io.Serializable;
import lombok.Data;
@Data
public class ConfigSettingValue implements Serializable {
private static final long serialVersionUID = 1L;
private final String key;
private Object value;
private final Object defaultValue;
private final Class<?> type;
public ConfigSettingValue(String key, Object value, Object defaultValue, Class<?> type) {
this.key = key;
this.value = value;
this.defaultValue = defaultValue;
this.type = type;
}
}
package de.tutorials.training.springconfig;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class SimpleComponent {
private ConfigSetting<String> stringProperty = new ConfigSetting<>("default");
private ConfigSetting<Integer> intProperty = new ConfigSetting<>(42);
private ConfigSetting<Boolean> booleanProperty = new ConfigSetting<>(false);
public void businessMethod(/*..*/) {
if(booleanProperty.get()) {
businessTransaction1();
}else {
businessTransaction2();
}
}
private void businessTransaction2() {
//process(stringProperty.get())
//...
}
private void businessTransaction1() {
//process(intProperty.get())
//...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment