You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltaspike.apache.org by "Mark Struberg (Jira)" <ji...@apache.org> on 2021/12/07 20:30:00 UTC

[jira] [Commented] (DELTASPIKE-1444) Create POJO and Record based Config

    [ https://issues.apache.org/jira/browse/DELTASPIKE-1444?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17454832#comment-17454832 ] 

Mark Struberg commented on DELTASPIKE-1444:
-------------------------------------------

Pull request for review is up here https://github.com/struberg/deltaspike/tree/DELTASPIKE-1444

> Create POJO and Record based Config
> -----------------------------------
>
>                 Key: DELTASPIKE-1444
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-1444
>             Project: DeltaSpike
>          Issue Type: New Feature
>      Security Level: public(Regular issues) 
>          Components: Configuration
>    Affects Versions: 1.9.5
>            Reporter: Mark Struberg
>            Assignee: Mark Struberg
>            Priority: Major
>             Fix For: 1.9.6
>
>
> Right now we only support Interface based configuration with the {{@Configuration}} annotation. We could also support injecting POJOs directly and even Java14 Records.
> E.g. a class 
> {code}
> public record Endpoint(String host, Integer port, String path){}
> {code}
> or with a parameter ct:
> {code}
> public class Endpoint {
>      private final String host;
>      ... 
>     public Endpoint(
>             @ConfigProperty(name="host") String host, 
>             @ConfigProperty(name="port") Integer port, 
>             @ConfigProperty(name="path") String path){
>         this.host = host;
>         ....
>     }
> }
> {code}
> Note that the {{@ConfigProperty}} annotation might get omitted if the class gets compiled with the {{javac -parameters}} option.
> or with a default ct and field parameters:
> {code}
> public class Endpoint {
>      private String host;
>      private Integer port;
>      private String path;
>      ... 
> }
> {code}
> Resolving of all the required properties must be performed atomically.
> The solution might either be done via the built-in algorithms as shown above, in which case the following call might be used to denote that a bean should get resolved which consists of mulitple attributes:
> {code}
> ServerEndpointPojoWithCt someServer = ConfigResolver.resolve("myapp.some.server")
>             .asBean(ServerEndpointPojoWithCt.class)
>             .getValue();
> {code} 
> or via an explicit Converter function:
> {code}
>         final ServerEndpointPojoWithCt someServer = ConfigResolver.resolve("myapp.some.server")
>             .asBean(ServerEndpointPojoWithCt.class, (cfg, key) -> new ServerEndpointPojoWithCt(
>             cfg.resolve(key + ".host").getValue(),
>             cfg.resolve(key + ".port").as(Integer.class).getValue(),
>             cfg.resolve(key + ".path").getValue());)
>             .getValue();
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)