title: UnsatisfiedDependencyException: Error creating bean with name 'homeController': Unsatisfied dependency expressed through field 'dao'
body: <p>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homeController': Unsatisfied dependency expressed through field 'dao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alienDao': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException:</p>
  
  <p><strong>HomeController.java</strong></p>
  
  <pre><code>package com.telusko.springmvc;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  
  
  import com.telusko.springmvc.dao.AlienDao;
  import com.telusko.springmvc.model.Alien;
  
  
  @Controller
  public class HomeController
  {
  
      @Autowired
       AlienDao dao;
  
      @ModelAttribute
      public void modelData(Model m) 
      {
      m.addAttribute("name","Aliens");
      }
  
      @RequestMapping("/")
      public String home()
      {
          return "index";
      }
  
      @GetMapping("getAliens")
      public String getAliens(Model m)
      {
          m.addAttribute("result", dao.getAliens());
          return "showAliens";
  
      }
  
      @RequestMapping("addAlien")
      public String addAlien(@ModelAttribute Alien a)
      {
  
          return "result";
  
      }
  }
  </code></pre>
  
  <p><strong>AlienDao.java</strong></p>
  
  <pre><code> package com.telusko.springmvc.dao;
      import java.util.List;
  
      import javax.transaction.Transactional;
  
      import org.hibernate.Session;
      import org.hibernate.SessionFactory;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.stereotype.Repository;
      import org.springframework.stereotype.Service;
  
      import com.telusko.springmvc.model.Alien;
  
      @Service
      @Repository
      public class AlienDao
      {
          @Autowired
          private SessionFactory sessionFactory;
  
          @Transactional
      public List&lt;Alien&gt; getAliens()
      {
          Session session = sessionFactory.getCurrentSession();
          List &lt;Alien&gt; aliens = session.createQuery("from Alien",Alien.class).list();
  
          return aliens;
      }
      }
  </code></pre>
  
  <p><strong>Alien.java</strong></p>
  
  <pre><code>package com.telusko.springmvc.model;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  
  @Entity
  public class Alien 
  {
      @Id
      private int aid;
      private String aname;
  
      public int getAid() {
          return aid;
      }
      public void setAid(int aid) {
          this.aid = aid;
      }
      public String getAname() {
          return aname;
      }
      public void setAname(String aname) {
          this.aname = aname;
      }
      @Override
      public String toString() {
          return "Alien [aid=" + aid + ", aname=" + aname + "]";
      }
  
  
  }
  </code></pre>
  
  <p><strong>index.jsp</strong></p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      Welcome to Telusko
  
      &lt;form action="addAlien" method="POST"&gt;
          Enter your id : &lt;input type="text" name="aid"&gt;&lt;br&gt;
          Enter your name : &lt;input type="text" name="aname"&gt;&lt;br&gt;
          &lt;input type="submit"&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>result.jsp</strong></p>
  
  <pre><code>    &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
          pageEncoding="ISO-8859-1" isELIgnored="false"%&gt;
      &lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;meta charset="ISO-8859-1"&gt;
      &lt;title&gt;Insert title here&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          Result is : ${alien}
  
          Welcome Back ${name}
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p><strong>showAliens</strong></p>
  
  <pre><code> &lt;%@ page language="java" contentType="text/html; 
      charset=ISO-8859-1"pageEncoding="ISO-8859-1" isELIgnored="false"%&gt;
      &lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;meta charset="ISO-8859-1"&gt;
      &lt;title&gt;Insert title here&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          ${result}
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p><strong>telusko-servlet.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
      &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:ctx="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt;
  
      &lt;ctx:component-scan base-package="com.telusko"&gt;&lt;/ctx:component-scan&gt;
      &lt;ctx:annotation-config&gt;&lt;/ctx:annotation-config&gt;
  
  
      &lt;bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt;
      &lt;property name="driverClass" value="com.mysql.jdbc.Driver"&gt;&lt;/property&gt;
      &lt;property name="jdbcUrl" value="jdbc:mysql://localhost:3306/telusko"&gt;&lt;/property&gt;
      &lt;property name="user" value="root"&gt;&lt;/property&gt;
      &lt;property name="password" value="12345678"&gt;&lt;/property&gt;
  
      &lt;property name="minPoolSize" value="5" /&gt;
      &lt;property name="maxPoolSize" value="10" /&gt;
      &lt;property name="maxIdleTime" value="30000" /&gt;
      &lt;/bean&gt;
  
  
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="myDataSource" /&gt;
      &lt;property name="packageToScan" value="com.telusko.springmvc.model" /&gt;
      &lt;property name="hibernateProperties"&gt;
      &lt;props&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;/props&gt;
      &lt;/property&gt;  
      &lt;/bean&gt;
  
  
  
      &lt;bean id="myTransactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven transaction-manager="myTransactionManager" /&gt;
  
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/views/"&gt;&lt;/property&gt;
          &lt;property name="suffix" value=".jsp"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;/beans&gt;
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;!DOCTYPE web-app PUBLIC
   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd" &gt;
  
  &lt;web-app&gt;
  
    &lt;servlet&gt;
    &lt;servlet-name&gt;telusko&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
  
     &lt;servlet-mapping&gt;
     &lt;servlet-name&gt;telusko&lt;/servlet-name&gt;
     &lt;url-pattern&gt;/&lt;/url-pattern&gt;
     &lt;/servlet-mapping&gt;
  
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>error Show</strong></p>
  
  <pre><code>HTTP Status 500 – Internal Server Error
  Type Exception Report
  
  Message Servlet.init() for servlet [telusko] threw exception
  
  Description The server encountered an unexpected condition that prevented it from fulfilling the request.
  
  Exception
  
  javax.servlet.ServletException: Servlet.init() for servlet [telusko] threw exception
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
      org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:688)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
      org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
      org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
      org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
      org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594)
      org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Unknown Source)
  Root Cause
  
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homeController': Unsatisfied dependency expressed through field 'dao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alienDao': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/telusko-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'packageToScan' of bean class [org.springframework.orm.hibernate5.LocalSessionFactoryBean]: Bean property 'packageToScan' is not writable or has an invalid setter method. Did you mean 'packagesToScan'?
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
      org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130)
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
  </code></pre>