I have the following POJO class Test.java, which is populated from a properties file using annotation @ConfigurationProperties. I saw the use of annotations @Requiredto make it mandatory.
Instead of defining annotations at the level of the setter method, are there any annotations or parameters in the annotations @Valuethat I can use to define conditions like Mandatory, NotNull, etc.
@Component
@ConfigurationProperties(prefix = "com.test")
public class Test {
private String name;
@Required
public void setName(String name) {
name = name;
}
public String getName(String name) {
name = name;
}
}
Is this the right and only way to make a particular attribute mandatory? What are other such annotations that I could use for such conditions or verification purposes?
source
share