title: Exception: java.io.NotSerializableException: org.springframework.jdbc.datasource.DriverManagerDataSource
body: <p>I created a spring project (Spring 4.0.2). I present the required files:</p>
  
  <p><strong>spring.xml</strong></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"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;
  
      &lt;bean id="employeeDAO" class="com.journaldev.spring.jdbc.dao.EmployeeDAOImpl"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="employeeDAOJDBCTemplate" class="com.journaldev.spring.jdbc.dao.EmployeeDAOJDBCTemplateImpl"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /&gt;
          &lt;property name="url" value="jdbc:sqlserver://localhost:1433;database=springdb"/&gt;
          &lt;property name="username" value="lm" /&gt;
          &lt;property name="password" value="pp" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Employee.java</strong></p>
  
  <pre><code>@Entity
  @Table(name="Employee")
  public class Employee {
      @Id      
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name = "id", unique = true, nullable = false)
      private int id;
  
      @Column(name = "name")
      private String name;
  
      @Column(name = "role")
      private String role;
  
      // with getters, setters, default constructor, constructor using fields
  }
  </code></pre>
  
  <p><strong>EmployeeDAO.java</strong></p>
  
  <pre><code>public interface EmployeeDAO 
  {
      public List&lt;Employee&gt; getAll();
  }
  </code></pre>
  
  <p><strong>EmployeeDAOImpl.java</strong></p>
  
  <pre><code>public class EmployeeDAOImpl implements EmployeeDAO {
      private DataSource dataSource;
  
      public void setDataSource(DataSource dataSource) {
          this.dataSource = dataSource;
      }
  
      @Override
      public List&lt;Employee&gt; getAll() {
          String query = "select id, name, role from Employee";
          List&lt;Employee&gt; empList = new ArrayList&lt;Employee&gt;();
          Connection con = null;
          PreparedStatement ps = null;
          ResultSet rs = null;
          try{
              con = dataSource.getConnection();
              ps = con.prepareStatement(query);
              rs = ps.executeQuery();
              while(rs.next()){
                  Employee emp = new Employee();
                  emp.setId(rs.getInt("id"));
                  emp.setName(rs.getString("name"));
                  emp.setRole(rs.getString("role"));
                  empList.add(emp);
              }
          }catch(SQLException e){
              e.printStackTrace();
          }finally{
              try {
                  rs.close();
                  ps.close();
                  con.close();
              } catch (SQLException e) {
                  e.printStackTrace();
              }
          }
          return empList;
      }
  }
  </code></pre>
  
  <p><strong>EmployeeDAOJDBCTemplateImpl.java</strong></p>
  
  <pre><code>public class EmployeeDAOJDBCTemplateImpl implements EmployeeDAO,Serializable {
      private DataSource dataSource;
  
      public void setDataSource(DataSource dataSource) {
          this.dataSource = dataSource;
      }
  
      @Override
      public List&lt;Employee&gt; getAll() {
          String query = "select id, name, role from Employee";
          JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
          List&lt;Employee&gt; empList = new ArrayList&lt;Employee&gt;();
  
          List&lt;Map&lt;String,Object&gt;&gt; empRows = jdbcTemplate.queryForList(query);
  
          for(Map&lt;String,Object&gt; empRow : empRows){
              Employee emp = new Employee();
              emp.setId(Integer.parseInt(String.valueOf(empRow.get("id"))));
              emp.setName(String.valueOf(empRow.get("name")));
              emp.setRole(String.valueOf(empRow.get("role")));
              empList.add(emp);
          }
          return empList;
      }
  }
  </code></pre>
  
  <p>The bean to call in order to extract the list of employees <strong>DataModelD.java</strong> :</p>
  
  <pre><code>@ManagedBean
  @ViewScoped
  public class DataModelD implements Serializable
  {
      private List&lt;Employee&gt; list;
      private Employee employee;
      private EmployeeDAO eDao;
  
      @PostConstruct
      public void init() 
      {
      System.out.println("-----------------------------BEGIN List");
  ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
  eDao = ctx.getBean("employeeDAOJDBCTemplate", EmployeeDAO.class);
      employee = new Employee();
      list = eDao.getAll();
      System.out.println("---------------------------------------List size= " + list.size());
      }
  }
  </code></pre>
  
  <p>After running it(to display the list of employees), the following exception is displayed:</p>
  
  <pre><code>08:14:46,222 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "HiSpring.war"
  08:15:29,271 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) -----------------------------BEGIN List
  
  08:15:29,529 INFO  [org.springframework.context.support.ClassPathXmlApplicationContext] (http-localhost-127.0.0.1-8080-1) Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@ca34ed: startup date [Wed Aug 17 08:15:29 GMT-08:00 2016]; root of context hierarchy
  08:15:29,591 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (http-localhost-127.0.0.1-8080-1) Loading XML bean definitions from class path resource [spring.xml]
  08:15:29,718 INFO  [org.springframework.jdbc.datasource.DriverManagerDataSource] (http-localhost-127.0.0.1-8080-1) Loaded JDBC driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
  08:15:30,736 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) ---------------------------------------List size= 5
  
  08:15:30,832 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (http-localhost-127.0.0.1-8080-1) Error Rendering View[/sarsoura/list.xhtml]: java.io.NotSerializableException: org.springframework.jdbc.datasource.DriverManagerDataSource
      at java.io.ObjectOutputStream.writeObject0(Unknown Source) [rt.jar:1.7.0_55]
      at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source) [rt.jar:1.7.0_55]
  </code></pre>
  
  <p>Have you please any idea about this issue?.Any reply will be appreciated.</p>