Reputation: 768
I have a service class like so :
@UnlessBuildProperty(name = "someservice.enabled", stringValue = "false")
@ApplicationScoped
public class SomeService{
@Scheduled(every = "${check.interval:1M}")
public void process() {
//do something
}
}
The intention is that the service class should not be instantiated at all in case the build property someservice.enabled
is false
. And if not specified or true
the service should be instantiated and the scheduled method in the service should execute every 1 minute.
However with the @UnlessBuildProperty
either the class is never instantiated or the scheduled method never executes.
Only when I comment out the above annotation does it work. What am I doing wrong ? And how should I fix this ?
Upvotes: 0
Views: 249
Reputation: 768
Update : the above code sample works.
However, the key thing to note is that by default if the property is absent the UnlessBuildProperty
is treated as false.
You also need to add the property explicitly to your application.properties
.
I did have a config like below and did not work. But adding the property explicitly to application.properties
works.
This does not work
@ConfigMapping(prefix = "someservice")
public interface SomeServiceConfig {
@WithName("enabled")
@WithDefault("true")
Optional<Boolean> enabled();
}
Discussion from : https://github.com/quarkusio/quarkus/discussions/39994
Upvotes: 0