0

I am facing a situation where a previously working config load stopped working after the Lombok builder annotation was added to a Config class.

What's more perplexing is that Spring doesn't even fail startup or even warn in logs about this.

Here is an example:

@Configuration
@Data
@ConfigurationProperties(prefix = "app.export")
public class ExportConfig {

    private String folderPath;
    private Integer capacity;
    private String filename;

    private Map<String, ExportClientConfig> clientConfigurations;

    public ExportClientConfig getClientConfiguration(String account){
        return clientConfigurations.get(account);
    }
}

Here, the Map<String, ExportClientConfig> usually gets loaded with all values from the application.yaml

However, once @Builder is enabled on the ExportClientConfig class, Spring quietly ignores the fact that its not able to construct ExportClientConfig during startup.

Relevant section of the application.yml:

app:
  export:
    folderPath: /data/app/export
    capacity: 50
    filename: data.txt
    clientConfigurations:
      ACC1:
        code: ACC1-ABC
        center: 1001
        payCode: SDLKFJS
      ACC2:
        code: ACC2-XYZ
        center: 2001
        payCode: DSFKHKSDJF

If the @Builder alone is reverted, everything works fine. Otherwise, the clientConfigurations map is empty.

Is this behaviour documented anywhere? Is this expeted in Spring or, is it a bug?

Teddy
  • 4,009
  • 2
  • 33
  • 55
  • Isn't @Builder one of a Project Lombok magical annotations? How would Spring know and be responsible for stuff Lombok does? If it's documented anywhere, I'd expect it to be on Lombok rather than Spring side – pafau k. May 29 '23 at 15:45
  • What did you expect when you put @Builder at a configuration class of spring? – Thilo Schwarz May 29 '23 at 16:35
  • If Spring is finding matching class for filling this structure `Map` , and is finding matching data in application.yml and is unable to construct it due to lack of default constructor, then I was expecting it would fail at startup when building ApplicationContext – Teddy May 30 '23 at 03:49
  • If Lombok is magic then what is Spring? Spring is even more magic? I fail to see reason for any attitude against Lombok. – Teddy May 30 '23 at 03:52
  • But, based on your comment, it looks like this is the normal behavior for Spring. That's helpful - thank you! – Teddy May 30 '23 at 03:56

0 Answers0