Fallback#
The io.smallrye.config.FallbackConfigSourceInterceptor
allows to fall back to another configuration name, by
providing a transformation function or just a simple key value map.
When a configuration name does not exist, there might be another configuration name that the config can fall back to provide the same expected behavior. The fallback function is only applied if the original resolved configuration name is not found and resolved to the fallback name.
package org.acme.config;
import io.smallrye.config.FallbackConfigSourceInterceptor;
public class MicroProfileConfigFallbackInterceptor extends FallbackConfigSourceInterceptor {
public MicroProfileConfigFallbackInterceptor() {
super(name -> name.startsWith("mp.config") ?
name.replaceAll("mp\\.config", "smallrye.config") :
name);
}
}
And registration in:
org.acme.config.MicroProfileConfigFallbackInterceptor
The MicroProfileConfigFallbackInterceptor
can fallback configuration names in the mp.config
namespace
to the smallrye.config
namespace.
Example
A lookup to mp.config.profile
returns the value test
.
A lookup to mp.config.profile
returns the value prod
. The config is not able to find a value for
mp.config.profile
, so the interceptor fallbacks and lookups the value of smallrye.config.profile
.