title: Autowiring not working
body: <p>Please help me with this error, I'm new to spring.</p>
  
  <p>This the stack trace: </p>
  
  <pre><code>12:23:16,350 ERROR [STDERR] java.lang.NullPointerException
      12:23:16,351 ERROR [STDERR]     at igate.service.ProgramsOfferedServiceImpl.retrievePrograms(ProgramsOfferedServiceImpl.java:39)
      12:23:16,351 ERROR [STDERR]     at org.apache.jsp.programs_jsp._jspService(programs_jsp.java:118)
      12:23:16,351 ERROR [STDERR]     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      12:23:16,351 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      12:23:16,351 ERROR [STDERR]     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
      12:23:16,351 ERROR [STDERR]     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
      12:23:16,351 ERROR [STDERR]     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
      12:23:16,351 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:687)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:403)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
      12:23:16,351 ERROR [STDERR]     at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
      12:23:16,351 ERROR [STDERR]     at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
      12:23:16,351 ERROR [STDERR]     at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
      12:23:16,351 ERROR [STDERR]     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
      12:23:16,351 ERROR [STDERR]     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
      12:23:16,351 ERROR [STDERR]     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
      12:23:16,351 ERROR [STDERR]     at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
      12:23:16,351 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
      12:23:16,351 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      12:23:16,351 ERROR [STDERR]     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      12:23:16,351 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      12:23:16,351 ERROR [STDERR]     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      12:23:16,351 ERROR [STDERR]     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      12:23:16,352 ERROR [STDERR]     at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      12:23:16,352 ERROR [STDERR]     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      12:23:16,352 ERROR [STDERR]     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
      12:23:16,352 ERROR [STDERR]     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      12:23:16,352 ERROR [STDERR]     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
      12:23:16,352 ERROR [STDERR]     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      12:23:16,352 ERROR [STDERR]     at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>This the code for data access:</p>
  
  <pre><code>package igate.dao;
  import java.sql.*;
  import java.util.ArrayList;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.jdbc.core.JdbcTemplate;
  import org.springframework.jdbc.core.RowMapper;
  import org.springframework.stereotype.Component;
  
  import igate.dto.ProgramsOffered;
  @Component
  public class ProgramsOfferedDataAccessImpl implements ProgramsOfferedDataAccess 
  {
      @Autowired
      JdbcTemplate template;
  
      public ProgramsOfferedDataAccessImpl() {
          // TODO Auto-generated constructor stub
      System.out.println("inside programs offered");
      }
  
      @Override
      public boolean DeleteProgramsOffered(String name)throws SQLException 
      {
          boolean rowsAffected = false;
          String delete = "DELETE FROM programs_offered WHERE program_name='"+name+"'";
          int r = template.update(delete);
          if(r&gt;0)
              rowsAffected=true;
          return rowsAffected;
      }
  
      @Override
      public ArrayList&lt;ProgramsOffered&gt; retrievePrograms() 
      {
          RowMapper&lt;ProgramsOffered&gt; row = new RowMapper&lt;ProgramsOffered&gt;()
          {
  
              @Override
              public ProgramsOffered mapRow(ResultSet rs, int arg1) throws SQLException 
              {
                  ProgramsOffered po = new ProgramsOffered();
                  po.setProgramName(rs.getString(1));
                  po.setDescription(rs.getString(2));
                  po.setApplicantEligibility(rs.getString(3));
                  po.setDuration(rs.getInt(4));
                  po.setDegreeCertificateOffered(rs.getString(5));
                  return po;
              }
  
          };
          String sql = "select * from programs_offered";
          System.out.println(template);
          return (ArrayList&lt;ProgramsOffered&gt;)template.query(sql, row);
      }
  
      @Override
      public boolean insertProgram(ProgramsOffered po) 
      {
          boolean rowsAffected = false;
          String insert = "insert into programs_offered values(?,?,?,?,?)";
          int r = template.update(insert);
          if(r&gt;0)
              rowsAffected=true;
          return rowsAffected;
      }
  
      @Override
      public boolean updateProgram(String progName, String colName, String newValue) 
      {
          return false;
      }
  
      @Override
      public boolean updateProgram(String progName, String colName, int newValue) 
      {
          return false;
      }
  
      public JdbcTemplate getTemplate() 
      {
          return template;
      }
  
      public void setTemplate(JdbcTemplate template) 
      {
          this.template = template;
      }
  }
  </code></pre>
  
  <p>This is my service layer. I am not able to get what the problem is here as I am auto wiring <code>ProgramsOffered poda</code> but I am still getting null pointer exception.</p>
  
  <pre><code>package igate.service;
  import java.sql.SQLException;
  import java.util.ArrayList;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Component;
  
  import igate.dao.*;
  import igate.dto.ProgramsOffered;
  @Component("offeredService")
  public class ProgramsOfferedServiceImpl implements ProgramsOfferedService 
  {
      @Autowired
      public ProgramsOfferedDataAccess poda;
  
  
      @Override
      public boolean DeleteProgramsOffered(String name)
      {
          boolean rowsaffected=false;
          try
          {
              rowsaffected = poda.DeleteProgramsOffered(name);
  
          }
          catch(SQLException e)
          {
              e.printStackTrace();
          }
          catch (Exception e) 
          {
              e.printStackTrace();
          }
          return rowsaffected;
      }
      @Override
      public ArrayList&lt;ProgramsOffered&gt; retrievePrograms() 
      {
          ArrayList&lt;ProgramsOffered&gt; al = poda.retrievePrograms();
          return al;
      }
      @Override
      public boolean insertProgram(ProgramsOffered po) 
      {
  
          return poda.insertProgram(po);
      }
      @Override
      public boolean updateProgram(String progName, String colName, String newValue) 
      {
  
          return poda.updateProgram(progName, colName, newValue);
      }
      @Override
      public boolean updateProgram(String progName, String colName, int newValue) 
      {
  
          return poda.updateProgram(progName, colName, newValue);
      }
      @Override
      public ArrayList&lt;ProgramsOffered&gt; programDetails(String programName) 
      {
          ArrayList&lt;ProgramsOffered&gt; list = new ArrayList&lt;ProgramsOffered&gt;();
          list = poda.retrievePrograms();
          System.out.println("to keep at 0 "+programName);
          System.out.println("list size:" +list.size());
          int size = list.size();
          for(int i = 0;i&lt;size;i++)
          {
              System.out.println(i);
              if(!list.get(i).getProgramName().trim().equals(programName))
              {
                  System.out.println("removing: "+list.get(i).getProgramName());
                  //list.remove(i);
              }
              else
              {
                  ProgramsOffered temp = new ProgramsOffered();
                  temp = list.get(0);
                  list.set(0, list.get(i));
                  list.set(i, temp);
                  System.out.println("at 0 prog: "+list.get(0));
              }
          }
          return list;
      }
  
  
  }
  </code></pre>
  
  <p>I am getting a null pointer exception on this line:
  <code>ArrayList&lt;ProgramsOffered&gt; al = poda.retrievePrograms();</code></p>
  
  <pre><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:context="http://www.springframework.org/schema/context"
          xmlns:mvc="http://www.springframework.org/schema/mvc"
          xmlns:aop="http://www.springframework.org/schema/aop"
          xmlns:tx="http://www.springframework.org/schema/tx"
          xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/aop
          http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt;
  
              &lt;mvc:annotation-driven /&gt;
              &lt;context:annotation-config/&gt;
              &lt;context:component-scan base-package="igate.dto" /&gt;
                  &lt;context:component-scan base-package="igate.dao" /&gt;
                      &lt;context:component-scan base-package="igate.service" /&gt;
                          &lt;context:component-scan base-package="igate.controller" /&gt;
                  &lt;context:component-scan base-package="igate.logs" /&gt;
                      &lt;context:component-scan base-package="igate.testcases" /&gt;
  
  
              &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
                    &lt;property name="prefix" value="/"/&gt;
                    &lt;property name="suffix" value=".jsp" /&gt;
              &lt;/bean&gt; 
  
  
              &lt;bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
                  &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /&gt;
                  &lt;property name="url" value="jdbc:oracle:thin:@172.21.17.5:1521:oraten" /&gt;
                  &lt;property name="username" value="lab01trg21" /&gt;
                  &lt;property name="password" value="lab01oracle" /&gt;
              &lt;/bean&gt;
  
              &lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt;
                  &lt;property name="dataSource" ref="ds"/&gt;
              &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>