title: Filters - Servlets and Spring beans integration NullPointerException
body: <p>I have filter executes before servlet:</p>
  
  <pre><code>    public class UserFilter implements Filter {
  
  
      List&lt;String&gt; sessionIdsList;
  
      WebContentDAOIF webContentDAOIF;
  
          public void setWebContentDAOIF(WebContentDAOIF webContentDAOIF) {
              this.webContentDAOIF = webContentDAOIF;
          }
  
  
          @Override
          public void init(FilterConfig arg0) throws ServletException {
  
                      sessionIdsList = new ArrayList&lt;String&gt;();
                      sessionIdsList = webContentDAOIF.fetchAllSessionIds();
  
              }
  
  
          @Override
          public void doFilter(ServletRequest request, ServletResponse response,
                                                       FilterChain filterChain) throws IOException, ServletException {
  
              System.out.println("List size: " + sessionIdsList.size());
  
                  HttpServletRequest httpRequest = (HttpServletRequest)request;
  
                  HttpSession session = httpRequest.getSession();
                  String userSessionId = session.getId();
                  System.out.println("Filter: " + userSessionId);
  
                  if(sessionIdsList.size() !=0 &amp;&amp; sessionIdsList.contains(userSessionId)) {
  
                          System.out.println("There is same sessionID");
  
                  } else {
  
                      System.out.println("Hello anonim");
  
                  }
  
                  RequestDispatcher dispatcher = request.getRequestDispatcher("main");
                  dispatcher.forward(request, response);
  
  
          }
  
  
          @Override
          public void destroy() {
  
  
              }
  
  
  }
  </code></pre>
  
  <p>And I have spring context xml file where I declare all my beans:</p>
  
  <pre><code>&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt; 
              &lt;property name="driverClassName"&gt;&lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt;&lt;/property&gt;
              &lt;property name="url"&gt;&lt;value&gt;jdbc:mysql://localhost:3306/contentDB&lt;/value&gt;&lt;/property&gt; 
              &lt;property name="username"&gt;&lt;value&gt;root&lt;/value&gt;&lt;/property&gt;
              &lt;property name="password" &gt;&lt;value&gt;25051988&lt;/value&gt;&lt;/property&gt;
  
          &lt;/bean&gt;
  
  
          &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
  
              &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;
              &lt;property name="mappingResources"&gt;
                  &lt;list&gt;
                      &lt;value&gt;user.hbm.xml&lt;/value&gt;
                      &lt;value&gt;userEvents.hbm.xml&lt;/value&gt;
                  &lt;/list&gt;
              &lt;/property&gt;
              &lt;property name="hibernateProperties"&gt;
                  &lt;props&gt;
  
                      &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
  
                      &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
                      &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                      &lt;prop key="hibernate.max_fetch_depth"&gt;3&lt;/prop&gt;
                      &lt;prop key="hibernate.jdbc.fetch_size"&gt;50&lt;/prop&gt;
                      &lt;prop key="hibernate.jdbc.batch_size"&gt;15&lt;/prop&gt;
                  &lt;/props&gt; 
  
              &lt;/property&gt;
  
          &lt;/bean&gt;
  
  
          &lt;bean id="webContentDAOImpl" class="demidov.pkg.persistence.WebContentDAOImpl"&gt;
              &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
          &lt;/bean&gt;
  
  
          &lt;tx:annotation-driven/&gt;
  
          &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
              &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
          &lt;/bean&gt;
  
  
          &lt;bean id="userFilter" class="demidov.pkg.web.UserFilter"&gt;
              &lt;property name="webContentDAOIF" ref="webContentDAOImpl"/&gt;
          &lt;/bean&gt;
  </code></pre>
  
  <p>I also have filter declared in my web.xml:</p>
  
  <pre><code> &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/*-context.xml&lt;/param-value&gt;
        &lt;/context-param&gt;
  
        &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
        &lt;/listener&gt;
  
        &lt;filter&gt;
          &lt;filter-name&gt;userFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;demidov.pkg.web.UserFilter&lt;/filter-class&gt;
        &lt;/filter&gt;
  
        &lt;filter-mapping&gt;
          &lt;filter-name&gt;userFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
        &lt;/filter-mapping&gt;
  
        &lt;servlet&gt;
          &lt;servlet-name&gt;initialContentRendering&lt;/servlet-name&gt;
          &lt;servlet-class&gt;demidov.pkg.web.InitialContentRendering&lt;/servlet-class&gt;
        &lt;/servlet&gt;
  
        &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;initialContentRendering&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/main&lt;/url-pattern&gt;
        &lt;/servlet-mapping&gt;
  
        &lt;servlet&gt;
          &lt;servlet-name&gt;orderEventServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;demidov.pkg.web.OrderEventServlet&lt;/servlet-class&gt;
        &lt;/servlet&gt;
  
        &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;orderEventServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/event&lt;/url-pattern&gt;
        &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>But when I load application it says me:</p>
  
  <pre><code>   SEVERE: Exception starting filter userFilter
      java.lang.NullPointerException
          at demidov.pkg.web.UserFilter.init(UserFilter.java:35)
          at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:273)
          at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:254)
          at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:372)
          at org.apache.catalina.core.ApplicationFilterConfig.&lt;init&gt;(ApplicationFilterConfig.java:98)
          at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4562)
          at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5240)
          at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5235)
          at java.util.concurrent.FutureTask.run(FutureTask.java:262)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
          at java.lang.Thread.run(Thread.java:724)
  </code></pre>
  
  <p>Please help me what I'm doing wrong.
  Thank you folks.</p>