Validating the State of Spring Beans - Take Two
Just an update to my previous post on the validation of Spring beans. Err, forget all that.
Spring 2.0 introduces the @Required annotation. You need to enable this in your config file:
<bean class =
“org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor”/>
And then you can annotate each required setter with @Required and Spring will barf on startup if that setter is missing from the Spring config.
It seems the annotation processor needs to be declared in each Spring config (if you have multiple config files, as I do).
I would still advocate writing and explicitly calling further validation code if you class needs it, but this is what you want in 99% of cases.