Skip to content
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

Bean validation in class annotated with ConfigProperties doesn't work #10848

Closed
Rutzzzz opened this issue Jul 20, 2020 · 1 comment · Fixed by #10854
Closed

Bean validation in class annotated with ConfigProperties doesn't work #10848

Rutzzzz opened this issue Jul 20, 2020 · 1 comment · Fixed by #10854
Assignees
Labels
kind/bug Something isn't working
Milestone

Comments

@Rutzzzz
Copy link
Contributor

Rutzzzz commented Jul 20, 2020

I was following the guide for Quarkus configuration - https://quarkus.io/guides/config#using-configproperties. The example with bean validation using class annotated with ConfigProperties doesn't seem to work as no errors are thrown when property violates bean validation annotations.

Expected behavior
An error is displayed when a property in application.properties has value violating bean validation annotation.

Actual behavior
No error is displayed.

To Reproduce

  1. Create the project
mvn io.quarkus:quarkus-maven-plugin:1.6.0.Final:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=config-quickstart \
    -DclassName="org.acme.config.GreetingResource" \
    -Dpath="/greeting"
cd config-quickstart
  1. Create the configuration class with following content:
@ConfigProperties(prefix = "greeting")
public class GreetingConfiguration {
    @Size(min = 20)
    public String message;
    public String suffix = "!";
}
  1. Add the following property to application.properties:
greeting.message = hello
  1. Inject the configuration to GreetingResource class
@Inject
GreetingConfiguration greetingConfiguration
  1. Output the configuration
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
     return greetingConfiguration.message + greetingConfiguration.suffix;
}
  1. Run the application
./mvnw quarkus:dev

Configuration

greeting.message = hello

Environment:

  • Output of uname -a or ver: Linux localhost.localdomain 5.6.13-100.fc30.x86_64 Switch to the Maven distributed copy of the SubstrateVM annotations #1 SMP Fri May 15 00:36:06 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  • Output of java -version:
    openjdk version "11.0.7" 2020-04-14
    OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02)
    OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02, mixed mode, sharing)
  • Quarkus version: 1.6.0.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
@Rutzzzz Rutzzzz added the kind/bug Something isn't working label Jul 20, 2020
@geoand geoand self-assigned this Jul 20, 2020
geoand added a commit to geoand/quarkus that referenced this issue Jul 20, 2020
@geoand
Copy link
Contributor

geoand commented Jul 20, 2020

Hi,

This turns out to be a docs problem. You need to add the quarkus-hibernate-validator extension to make it work. I opened #10854 to fix the docs.

gsmet added a commit that referenced this issue Jul 20, 2020
Mention validator extension with @ConfigProperties
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jul 20, 2020
@gsmet gsmet added this to the 1.6.1.Final milestone Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants