Is there a way to manually register and/or disable ConfigMappings? #30970
Replies: 2 comments 1 reply
-
I have some progress. So ultimately I was able to have that "optional" configmapping by doing the following; 1- Remove ConfigMappings.registerConfigMappings(ConfigProvider.getConfig().unwrap(SmallRyeConfig.class),
Set.of(new ConfigMappings.ConfigClassWithPrefix(MyServiceConfig.class, "service")));
return new MyService(); 3-I have another producer that creates the CDI dependent bean as // Note not having the prefix in the getConfigMappin does not work, that was my initial mistake in the OP
return ConfigProvider.getConfig().unwrap(SmallRyeConfig.class).getConfigMapping(MyServiceConfig.class,"service") The only problem I have now is that I am unable to achieve the bean validation my formerly I tried doing it manually this way; but the validation always passes, I'd appreciate some pointers one how to get that one last piece work. cc @radcortez // config is from SmallRyeConfig#getConfigMapping
ConfigValidator validator = new BeanValidationConfigValidatorImpl();
validator.validateMapping(MyServiceConfig.class, "service", config); |
Beta Was this translation helpful? Give feedback.
-
Are you applying the Some time ago, in #19965, we no longer registered mappings injected in unused / removed beans. So if you have an injection in an unused bean the mapping should not be registered. I've tried this scenario in a sample project, and it seems to work, but I might be missing something. I guess that your beans are annotated with Can you send a reproducer to check the setup and investigate the problem? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
We have multiple services (beans), all implementing the same interface. For now we use
IfBuildProperty
to select which one will be used at runtime. Each build has it's own configuration file, added this wayquarkus.config.locations=${service}/${service}.properties
. These are mapped with@ConfigMapping
.I have few problems with this architecture, that I am not sure what would be the best way to solve.
1-
@IfBuildProperty(name = Service.property, stringValue = Service.Constants.FirstService)
this seem to disable the dependent bean created, but still loads the config at startup, so when I switch to another service / another config this will fail the quarkus' startup, as the "first service"' config is not available, which is what I expect.
2- I then tried to not use
IfBuildProperty
to have everything modifiable at runtime, seems to work for my service as I can select via a Producer method. But I am not able to achieve the same for the ConfigMapping. I tried to remove the@ConfigMapping(prefix = "prefix")
and@StaticInitSafe
from the class and register it myself in a producer method, something like this;But then the getConfigMapping fails, so I am unsure what would be the best way to achieve sort of optional ConfigMapping.
Also try using the
SmallRyeConfigBuilder
a bit like this but was also unsuccessfulHelp would be appreciated.
Thanks,
Alex
Beta Was this translation helpful? Give feedback.
All reactions