In Spring, how do you ensure that all properties are set on a particular bean?

Answered

In Spring, how do you ensure that all properties are set on a particular bean?

Ninja Asked on 17th September 2018 in Spring.
Add Comment
1 Answer(s)
Best answer

The Spring container also has the ability to check for the existence of unresolved dependencies of a bean deployed into the container. These are properties of the bean, which do not have actual values set for them in the bean definition, or alternately provided automatically by the autowiring feature. Spring container provides a dependency checking mechanism for a bean which can be specified through dependency-check attribute of a bean when using XML-based configuration.

Various dependency checking modes supported and their behavior is provided below:

• none – This is the default mode and implies that dependency check will not be performed.
• simple – Dependency Check is performed for primitive types and collections
• object – Dependency Check is performed for objects
• all – Dependency Check is done for all objects, primitive types and collections

For annotation based configuration, this can be achieved using @Required annotation in in the org.springframework.beans.factory.annotation package.

Ninja Answered on 17th September 2018.
Add Comment