-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't @Inject a @ConfigMapping Interface on a Validator #23879
Comments
Please provide a reproducer (and also add the error you obtain in the description). |
Sorry, should have done that immediately. Config class: @StaticInitSafe
@ConfigMapping(prefix = "app")
public interface AppConfig {
@WithName("feature-property")
FeatureProperty featureProperty();
interface FeatureProperty {
@WithDefault("0.5")
double configPercentage();
}
} Validator class: @ApplicationScoped
public class CreateEntityValidator implements ConstraintValidator<CreateEntityValidator , EntityRequest> {
// This way it works
// @ConfigProperty(name = "app.feature-property.config-percentage")
// double configPercentage;
@Inject
protected AppConfig appConfig;
public boolean isValid(final EntityRequest entityRequest,
final ConstraintValidatorContext constraintValidatorContext) {
this.isValid = true;
this.errorMessage = new StringBuilder();
constraintValidatorContext.disableDefaultConstraintViolation();
if (teamSpaceMaxCapacity < Math.ceil((double) placeCapacity * appConfig.featureProperty().configPercentage())) {
this.isValid = false;
}
return isValid;
}
} Error:
|
@nunocasteleira thank you. Unfortunately, this is not enough. If I copy-paste your code, there are still missing things and I'm unable to get a running reproducer. I could fill in the blanks, but it could deviate from your original issue. Are you able to provide a small GH repo, with a working example? Thank you. |
@radcortez I'm not able to reproduce this error on a clean project, so clearly I'm doing something wrong. In theory this is what I want to do and on this repo it is working: https://github.com/nunocasteleira/quarkus-error-on-validation |
I had a quick look and the reproducer is missing the dependency for the runtime Hibernate Validator (the Validator API is available because of RESTEasy, but they are not being read). I don't get the same stacktrace as you, but I noticed an issue where we have a circular dependency between the config mapping and the Validator. The issue is that because the Validator is available, we will try to validate the mapping, but the Validator tries to create the For now, a way to fix it is to just inject an
|
Also, because you are retrieving the mapping programmatically, you need to annotate it with |
Thanks for the replies. Just to be sure, Is this approach better than using |
You still conserve the mapping, you just retrieve it programmatically lazyly to break up the circular dependency. |
Describe the bug
I implemented a
@ConfigMapping
Interface to pass configurations viaapplication.yaml
file, annotated it with@StaticInitSafe
but I can't build my app when I@Inject
it on a@ApplicationScoped
ConstraintValidator
.I already was using Configurations with the
@ConfigProperty(name = "configname")
annotation and it works, but I implemented configurations via the interface as I'm understanding that it was deprecated and I needed to mock it.Am I doing something wrong or is it a bug?
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
No response
Output of
uname -a
orver
No response
Output of
java -version
Oracle JDK 11
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.7.0.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Additional information
No response
The text was updated successfully, but these errors were encountered: