When trying to inject MyConfig
annotated with @ConfigProperties
into MyClass
, build fails with:
...
Caused by: jakarta.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type mycompany.thing.logging.MyConfig and qualifiers [@Default]
- injection target: parameter 'cfg' of mycompany.thing.logging.MyClass constructor
- declared on CLASS bean [types=[mycompany.thing.logging.MyClass, java.lang.Object], qualifiers=[@Default, @Any], target=mycompany.thing.logging.MyClass]
The following classes match by type, but have been skipped during discovery:
- mycompany.thing.logging.MyConfig was annotated with @Vetoed
MyConfig
class:
@ConfigProperties(prefix = "mycompany.thing.logs")
@Dependent
public class MyConfig {
@ConfigProperty(name = "sizeLimit", defaultValue = "5G")
ByteAmount sizeLimit;
@ConfigProperty(name = "useVDisk", defaultValue = "false")
boolean useVdisk;
@ConfigProperty(name = "workerInterval", defaultValue = "PT0.1S")
Duration workerInterval;
@ConfigProperty(name = "maintenanceInterval", defaultValue = "PT15M")
Duration maintenanceInterval;
//getters
}
MyClass
class:
@ApplicationScoped
@Startup
public class MyClass {
//fields
@Inject
public MyClass(
@ConfigProperty(name = "mycompany.thing.storage.data.stuff")
Path filedir,
@ConfigProperty(name = "mycompany.thing.storage.keepStuffFor", defaultValue = "P7D")
Duration keepStuffFor,
MyConfig cfg,
@ConfigProperty(name = "quarkus.log.console.format")
String pattern,
ScheduledExecutorService ses
) {
//construct
}
//rest of class
}
The workarround is to remove the @ConfigProperties
annotation and specify the prefix on each field
The MyConfig
class is based on: https://download.eclipse.org/microprofile/microprofile-config-3.0/microprofile-config-spec-3.0.html#_aggregate_related_properties_into_a_cdi_bean