Skip to content

Quarkus 3.16.x: Configuration mapping & validation not working #44705

Answered by radcortez
joschi asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, do it like this:

@Startup
@ApplicationScoped
public class AppScopedStartup {
    @Inject
    ApplicationConfig applicationConfig;

    @PostConstruct
    void postConstruct() {
        // This shouldn't happen if the configuration was validated
        if (applicationConfig.port() > 10000) {
            throw new RuntimeException("NOOOOOOO! Value: " + applicationConfig.port());
        }
    }
}

If you inject the mappings, the validation is triggered, and you don't even need the @Unremoveable annotation.

BTW, if you have a mapping, you might as well just use it instead of injecting @ConfigProperty(name = "application.port") int port

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
9 replies
@joschi
Comment options

@radcortez
Comment options

@joschi
Comment options

@radcortez
Comment options

Answer selected by joschi
@joschi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
3 participants