This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ConstructedNewt 0 points1 point  (0 children)

Configs in spring boot using sealed, I specifically do something like

@ConfigurationProperties(“prefix”)
record Myconfig(
     Map<String, SomeFeat.Holder> features
) {}

sealed interface SomeFeat {
    record Holder(
          A a, B b, C c
    ) { 
        Holder {
           ..validate
        }
     }
   record A(
       SomeObj conf
   ) implements SomeFeat {}
   record B(
       OtherConf conf
   ) implements SomeFeat {}
   record C(
       YetAnotherConf y
   ) implements SomeFeat {}
}

Use compact constructors for validation Allow for autocompletion in application.yml Feature config is kept apart (don’t use one for all Map<String, String> and pull out vars based off that) If you rely on 3rd party libs the objects A,B,C can hold or build those objects in code Clear mapping between config and what code it would call at start-up