Features
@ToggleOnFlag — Declarative Flag Gating
An annotation (org.iromu.openfeature.boot.aop.ToggleOnFlag) that gates a method — or every method in a class — on a boolean feature flag.
Attributes
key— the flag key to evaluate.attributes— a SpEL map for the evaluation context, e.g."{'userId': #id}". Method parameters are exposed as SpEL variables by name.orElse— name of a fallback method (same parameter types) invoked when the flag is false.
Behavior
ToggleOnFlagAspect (an @Aspect, registered by AspectAutoConfiguration, and @ConditionalOnBean(Client.class)) wraps matching methods with around advice:
- The method-level annotation wins over the class-level one.
attributes(when not"{}") is evaluated with SpEL into aMap<String, Value>; unknown keys throw.- The flag is evaluated with
client.getBooleanValue(key, false[, context])— default is false, so a missing flag disables the method. - Flag true → original method runs. Flag false → the
orElsefallback is invoked reflectively. No annotation → normal execution.
Example
@GetMapping("annotated/user/{id}")
@ToggleOnFlag(key = "users-flag", attributes = "{'userId': #id}", orElse = "featureOnUserIdDisabled")
public String featureOnUserIdAnnotated(@PathVariable("id") final String id) { ... }
Evaluation details: flows/flag-evaluation. Known rough edges (debug System.out.println, reflective fallback): risks/fragile-behavior.