I have a bean Config that has a required setter. However, when I don’t set the setting in the bean config file I don’t get an exception regarding the missing attribute.
public class Config extends MatchSet{
...
@Required
public void setSections(List<Section> section){...}
}
public class OtherClass{
...
@Required
public void setMatchSets(List<MatchSet> sets){...}
}
public interface MatchSet{...}
If I don’t include the matchSets field of OtherClass I get a BeanInitializationException. But if I don’t set the sections field of Config I don’t get the exception. I am passing the instance of Config as one of the elements of the MatchSet list passed to OtherClass.
I have tried this using unit tests (SpringJUnit4ClassRunner) and using my main (ClassPathXmlApplicationContext) and the behavior is the same in either case.
Why is the @Required attribute not being checked for Config? Is it because it is being passed as a MatchSet?
Thanks
Turns out this was caused by a different issue. I did not have the getter/setter set up correctly. Primarily, this was because I had tried to set up method chaining and so was not returning
nullfrom the setter. Also, I was accepting aListin the setting but returning anImmutableListfrom the getter. The combination was causing Spring to not recognize the setter and therefore not check