Skip to content

@ConfigMapping not working in non-CDI context? #22421

Closed Answered by edufolly
edufolly asked this question in Q&A
Discussion options

You must be logged in to vote

Follow @mkouba answer:

application.properties

server.host=https://myserver.com/client

ServerConfig.java

@ConfigMapping(prefix = "server")
public interface ServerConfig {

    String host();

}

ServerClient.java

@ApplicationScoped
public class ServerClient {

    @Inject
    ServerConfig server;

    public String get() {
        return server.host();
    }

}

ServerResource.java

@Path("/api/v1/server")
public class ServerResource {

    @Inject
    ServerClient client;

    @GET
    public String getServer() {
        return client.get();
    }

}

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@edufolly
Comment options

@radcortez
Comment options

@mkouba
Comment options

@edufolly
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by edufolly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area/arc Issue related to ARC (dependency injection)
3 participants