开发者

@Required attribute checked for one bean but not another

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<Mat开发者_StackOverflowchSet> 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 null from the setter. Also, I was accepting a List in the setting but returning an ImmutableList from the getter. The combination was causing Spring to not recognize the setter and therefore not check

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜