Why setters are mandatory for fields in a class which reads properties from application.yml file in springboot?

Following is my code:

Why setter is mandatory. Without it, the class does not read the property from the application.yml file correctly.

Thank you.

@ConfigurationProperties(prefix = "test")
public class KafkaTopicConfig {

    private String bootstrapAddress;

    @Value(value = "${test.bootstrapAddress}")
    private String bootstrapAddressFromVariable;

Read more here: https://stackoverflow.com/questions/68457583/why-setters-are-mandatory-for-fields-in-a-class-which-reads-properties-from-appl

Content Attribution

This content was originally published by thapa at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: