title: getting null pointer exception because can't create bean
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   default-autowire="byName"
   xmlns:oxm="http://www.springframework.org/schema/oxm"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-4.3.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"&gt;
   &lt;bean id="userRoleDAOTarget"
    class="com.revguru.crs.security.dao.UserRoleDAOImpl"
    scope="prototype"&gt;
    &lt;property name="sessionFactory" ref="hsdSessionFactory" /&gt;
   &lt;/bean&gt;
   &lt;bean id="userAuthDAOTarget" class="com.revguru.crs.security.dao.AuthenticationDAOImpl" scope="prototype"&gt;
    &lt;property name="sessionFactory" ref="hsdSessionFactory" /&gt;
   &lt;/bean&gt;
   &lt;bean id="hotelUserDAOTarget" class="com.revguru.crs.security.dao.HotelUserDAOImpl" scope="prototype"&gt;
    &lt;property name="sessionFactory" ref="hsdSessionFactory" /&gt;
   &lt;/bean&gt;
   &lt;bean id="userRoleDataObjprocessor" class="com.revguru.crs.security.service.UserRoleProcessor" scope="prototype"&gt;
    &lt;property name="userRoleDAO" ref="hsdSecurityObjectDAO" /&gt;
   &lt;/bean&gt;
   &lt;bean id="userAuthDataObjprocessor" class="com.revguru.crs.security.service.AuthenticationProcessor" scope="prototype"&gt;
    &lt;property name="authenticationDAO" ref="hsdSecurityAuthObjectDAO" /&gt;
    &lt;property name="messages" ref="userSectionMessageSource"/&gt; 
   &lt;/bean&gt;
   &lt;bean id="hotelUserDataObjProcessor" class="com.revguru.crs.security.service.HotelUserProcessor" scope="prototype"&gt;
    &lt;property name="hotelUserDAO" ref="hsdHotelUserDAO" /&gt;
    &lt;property name="securitySectionLogger" ref="generalServiceLogger"/&gt;
   &lt;/bean&gt;
   &lt;bean id="SECURITY_SERVICE" class="com.revguru.crs.core.service.sc.SecurityService" scope="prototype"&gt;
    &lt;property name="userRoleProcessor" ref="userRoleDataObjprocessor" /&gt;
    &lt;property name="userAuthProcessor" ref="userAuthDataObjprocessor" /&gt;
    &lt;property name="hotelUserProcessor" ref="hotelUserDataObjProcessor" /&gt;
   &lt;/bean&gt;
   &lt;bean id="hsdSecurityObjectDAO" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;
    &lt;property name="proxyInterfaces"&gt;
     &lt;value&gt;com.revguru.crs.security.dao.UserRoleDAO
     &lt;/value&gt;
    &lt;/property&gt;
    &lt;property name="interceptorNames"&gt;
     &lt;list&gt;
      &lt;value&gt;hibernateInterceptor&lt;/value&gt;
      &lt;value&gt;userRoleDAOTarget&lt;/value&gt;
     &lt;/list&gt;
    &lt;/property&gt;
   &lt;/bean&gt;
  
   &lt;bean id="hsdSecurityAuthObjectDAO" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;
    &lt;property name="proxyInterfaces"&gt;
     &lt;value&gt;com.revguru.crs.security.dao.AuthenticationDAO
     &lt;/value&gt;
    &lt;/property&gt;
    &lt;property name="interceptorNames"&gt;
     &lt;list&gt;
      &lt;value&gt;hibernateInterceptor&lt;/value&gt;
      &lt;value&gt;userAuthDAOTarget&lt;/value&gt;
     &lt;/list&gt;
    &lt;/property&gt;
   &lt;/bean&gt;
   
   &lt;bean id="hsdHotelUserDAO" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;
    &lt;property name="proxyInterfaces"&gt;
     &lt;value&gt;com.revguru.crs.security.dao.HotelUserDAO
     &lt;/value&gt;
    &lt;/property&gt;
    &lt;property name="interceptorNames"&gt;
     &lt;list&gt;
      &lt;value&gt;hibernateInterceptor&lt;/value&gt;
      &lt;value&gt;hotelUserDAOTarget&lt;/value&gt;
     &lt;/list&gt;
    &lt;/property&gt;
   &lt;/bean&gt;
   &lt;bean id="userSectionMessageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource" scope="prototype"&gt;
    &lt;property name="alwaysUseMessageFormat" value="true"/&gt;
    &lt;property name="basenames"&gt;
     &lt;list&gt;
      &lt;value&gt;userauthResources/hsd_user_msg&lt;/value&gt;    
     &lt;/list&gt;
    &lt;/property&gt;
   &lt;/bean&gt; 
  &lt;/beans&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>this is my bean file and it is getting reference to hsdsessionFsctory wich is defined as below:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"&gt;
    &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
    &lt;property name="url" value="jdbc:mysql://127.0.0.1:3306/revguru"/&gt;
    &lt;property name="username" value="root" /&gt;
    &lt;property name="password" value="decoder" /&gt;
   &lt;/bean&gt;
   
   &lt;bean id="hsdSessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"&gt;
    &lt;property name="dataSource" ref="dataSource" /&gt;
    &lt;property name="hibernateProperties"&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and when i run my project i get null pointer exception</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public class UserLoginController {
   
   private FacesContext facesContext = FacesContext.getCurrentInstance();
   HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true);
   private SecurityService securityService;
   
   public void setSecurityService(SecurityService securityService) {
    this.securityService = securityService;
   }
   
   public SecurityService getSecurityService() {
    return this.securityService;
   }
   
   /**
    * Authenticate the User
    * @return 
    */
   public String authenticate() {
    if(session.getAttribute("menus") != null) {
     session.removeAttribute("menus");
    }
    
    if (session.getAttribute("CommonGlobalBean") != null) {
     session.removeAttribute("CommonGlobalBean");
    }
    
    CommonGlobalBean commonGlobalBean = new CommonGlobalBean();
    commonGlobalBean.setTimeZone(TimeZone.getDefault().getID());
  
    UserLogin userLogin =(UserLogin)session.getAttribute("UserLogin");
    
    String username = userLogin.getUserName();
    String password = userLogin.getPassword();
    
    UserInformation userInformation = null; 
    System.out.println("security serv ice  is ");
    if(securityService==null){
     System.out.println("security serv ice  is null:");
     securityService= new SecurityService();
    }
    if (userLogin != null) {
     System.out.println("username is:"+username);
     System.out.println("password is:"+password);
     
     if (securityService.authenticate(username,password)) {
      Util.log("Get User Object by Email");
      UserDataObject userDataObject = securityService.getUserObjectByEmail(userLogin.getUserName());
      Util.log("User name : "+userDataObject.getUserFirstName());
      userInformation = (UserInformation)session.getAttribute("UserObject");
      if (userInformation != null) {
       session.removeAttribute("UserObject");
      }
      userInformation = getUserInformation(userDataObject);
      session.setAttribute("UserObject", userInformation);
        
      if(!checkUserAsHotelRole(userInformation)) {
       Util.log("User does not have hotel role.");
       Util.reportError(facesContext, "login_user_not_valid_password", null);
      }
  
      HotelDataObject hotelDataObject = getAssignedHotel(userInformation);
      session.setAttribute("hotelDataObjectInSession", hotelDataObject);
      
      List&lt;Menu&gt; menus = new ArrayList&lt;Menu&gt;();
      for (FeatureDataObject feature : userInformation.getFeatureDataObjects()) {
       if (feature.getParentFeatureId() == null &amp;&amp; feature.getFeatureTypeId().getId().intValue() == HSDServiceConstants.MENU &amp;&amp; feature.getShowFeature() == 1) {
        List&lt;MenuItem&gt; menuItems = getMenuItems(feature.getId(), userInformation.getFeatureDataObjects());
        menus.add(new Menu(feature.getId(), feature.getFeatureName(), "", menuItems));
       }
      }
   
      String languageCode = userLogin.getLanguageCode();  
        
      if (languageCode == null) {
       userLogin.setLanguageCode("en");
       facesContext.getViewRoot().setLocale(Locale.ENGLISH);
      } else {
       if(languageCode.equals("fr")) {
        facesContext.getViewRoot().setLocale(Locale.FRENCH);
       } else {
        facesContext.getViewRoot().setLocale(Locale.ENGLISH);
       }
      }
      
      Util.log(":: languageCode :: " + userLogin.getLanguageCode());
      
      session.setAttribute("menus", menus);
      session.setAttribute("CommonGlobalBean", commonGlobalBean);
      /**
       * get hotel general info details
       */
      GeneralHotelController generalHotelController = new GeneralHotelController();
      generalHotelController.loadGeneralInformation();
      /**
       * return to hotel general info page
       */
      return "generalInfo";
     } else {
      Util.log("Invalid User.");
      Util.reportError(facesContext, "login_user_not_valid_password", null);
     }
    } 
    return "";
   } </code></pre>
  </div>
  </div>
  </p>
  
  <p>which call another method to class as follow</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public boolean authenticate(String email, String password) {  
    log.info("Authenticating : " + email);
    UserDataObject user = getUserObjectByEmail(email);
    if (user == null) {
     log.info("User does not exist for email id :" + email);
     return false;
    }
    return checkPassword(password, user.getPassword());
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>when i see it in my spring explorer it shows me Bean ref is unknown</p>
  
  <p>this is my stack trace</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>javax.servlet.ServletException: java.lang.NullPointerException
  javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
  io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
  io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
  org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
  io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
  io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
  io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
  io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
  io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
  org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
  io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
  io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
  io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
  io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
  io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
  io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
  io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
  io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
  io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
  io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
  io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
  io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
  io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
  io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
  io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
  io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
  io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
  io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
  io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
  io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
  io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
  io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
  io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
  io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
  io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
  io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  java.lang.Thread.run(Thread.java:745)</code></pre>
  </div>
  </div>
  </p>
  
  <p>whats is red mark in my spring explorer</p>
  
  <p><a href="https://i.stack.imgur.com/Rez0O.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rez0O.jpg" alt="enter image description here"></a></p>
  
  <p>while others don't have it</p>