Spring @Required

@Required 

The @Required annotation applies to bean property setter methods, as in the following example:

public class SimpleMovieLister { 
 private MovieFinder movieFinder; 
 @Required public void setMovieFinder(MovieFinder movieFinder) {
 this.movieFinder = movieFinder; 
 } // ...
}

This annotation simply indicates that the affected bean property must be populated at configuration time, through an explicit property value in a bean definition or through autowiring. The container throws an exception if the affected bean property has not been populated; this allows for eager and explicit failure, avoiding NullPointerExceptions or the like later on. It is still recommended that you put assertions into the bean class itself, for example, into an init method. Doing so enforces those required references and values even when you use the class outside of a container. 

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation