Spring : Are Setter Methods in a class will be get called first with Spring?

I have a question with respect to Spring , please excuse if my Question is a dumb one . Please see this code

public class HomePageController extends AbstractController {

        private GeekNewsService service;

      protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse res) throws Exception {
      List<NewsArticle> articles = service.getArticleOverviews();
      return new ModelAndView( "home", "articles", articles );
     }

    public void setGeekNewsService( GeekNewsService service ) {
      this.service = service;
   }

}

Here my question is that , inside the handleRequestInternal Method , why there wasn't any NullPointerException at this line service.getArticleOverviews() ?? ( Because the actual Object Creation will happen with the help of SetterInjection at setMethod )??

Is there any rule in Spring that , when a class has been called the setXXX Methods must be invoked at first ??

Answers


Yes, this is the basic contract Spring is giving to you: before it returns any bean you are guaranteed that this bean is initialized based on your configuration. In other words you will never be capable of calling any business method of any bean prior to full initialization of that bean (setter injection, field injection, post construction callbacks).


Need Your Help

Trigger Hibernate(pre/post)Update Event when Relationship Changes

hibernate orm coldfusion coldfusion-10

I have implemented the pre/post event listeners for Hibernate events with one caveat I haven't been able to overcome. I have a Departments entity that has a many-to-many relationship back to a Cent...

A lot of long-lived access_tokens invalidated by Facebook with no reason

facebook migration access-token

I'm having this issue since offline_access has been deprecated and migration enabled.