Skip to content
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: 3 comments 15 replies

Comment options

You must be logged in to vote
0 replies
Comment options

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

@radcortez
Comment options

@joschi
Comment options

@radcortez
Comment options

Answer selected by joschi
@joschi
Comment options

@gsmet
Comment options

@radcortez
Comment options

@RomainWilbert
Comment options

Comment options

You must be logged in to vote
1 reply
@radcortez
Comment options

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