Search code examples
javaspringdependency-injectionjsr330

fail for null arguments with @Inject


I've started using Spring 3 Java Config with the JSR-330 @Inject annotations. Unlike the Spring @Autowire, Spring does not fail at startup if the @Inject parameters are null. Is there a way to do this within Java Config?

Edit: Just a clarification, I would like this as the default behaviour so I don't have to put @Required on every field.


Solution

  • I think you can use @Required on a setter for the dependency, in addition to @Inject.