title: Exception encountered during context initialization - Incompatible library?
body: <p>I follow <a href="http://websystique.com/springmvc/spring-4-mvc-and-hibernate4-integration-example-using-annotations/" rel="nofollow">this tutorial</a> but after all I get an error, and I don't understand why!!!</p>
  
  <p>This is my pom.xml</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;SpringExample&lt;/groupId&gt;
  &lt;artifactId&gt;SpringExample&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
          &lt;version&gt;4.2.6.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
          &lt;version&gt;3.1.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
          &lt;artifactId&gt;javax.servlet.jsp-api&lt;/artifactId&gt;
          &lt;version&gt;2.3.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
          &lt;version&gt;1.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
          &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
          &lt;version&gt;5.2.4.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.validation&lt;/groupId&gt;
          &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
          &lt;version&gt;1.1.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.1.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
          &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.39&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;joda-time&lt;/groupId&gt;
          &lt;artifactId&gt;joda-time&lt;/artifactId&gt;
          &lt;version&gt;2.9.3&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.jadira.usertype&lt;/groupId&gt;
          &lt;artifactId&gt;usertype.core&lt;/artifactId&gt;
          &lt;version&gt;5.0.0.GA&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;pluginManagement&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.2&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.4&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;warSourceDirectory&gt;src/main/webapp&lt;/warSourceDirectory&gt;
                      &lt;warName&gt;SpringExample&lt;/warName&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p>this is my controller</p>
  
  <pre><code>package org.dstech.examplespring.controller;
  
  import java.util.List;
  import java.util.Locale;
  
  import javax.validation.Valid;
  
  import org.dstech.examplespring.model.Employee;
  import org.dstech.examplespring.service.EmployeeService;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.MessageSource;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.validation.BindingResult;
  import org.springframework.validation.FieldError;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  /**
   * @author franksisca
   *c
   */
  @Controller
  @RequestMapping("/")
  public class AppController {
  
      @Autowired
      EmployeeService service;
  
      @Autowired
      MessageSource messageSource;
  
      /*
       * This method will list all existing employees.
       */
      @RequestMapping(value = { "/", "/list" }, method = RequestMethod.GET)
      public String listEmployees(ModelMap model) {
  
          List&lt;Employee&gt; employees = service.findAllEmployees();
          model.addAttribute("employees", employees);
          return "allemployees";
      }
  
      /*
       * This method will provide the medium to add a new employee.
       */
      @RequestMapping(value = { "/new" }, method = RequestMethod.GET)
      public String newEmployee(ModelMap model) {
          Employee employee = new Employee();
          model.addAttribute("employee", employee);
          model.addAttribute("edit", false);
          return "registration";
      }
  
      /*
       * This method will be called on form submission, handling POST request for
       * saving employee in database. It also validates the user input
       */
      @RequestMapping(value = { "/new" }, method = RequestMethod.POST)
      public String saveEmployee(@Valid Employee employee, BindingResult result,
              ModelMap model) {
  
          if (result.hasErrors()) {
              return "registration";
          }
  
          /*
           * Preferred way to achieve uniqueness of field [ssn] should be implementing custom @Unique annotation 
           * and applying it on field [ssn] of Model class [Employee].
           * 
           * Below mentioned peace of code [if block] is to demonstrate that you can fill custom errors outside the validation
           * framework as well while still using internationalized messages.
           * 
           */
          if(!service.isEmployeeSsnUnique(employee.getId(), employee.getSsn())){
              FieldError ssnError =new FieldError("employee","ssn",messageSource.getMessage("non.unique.ssn", new String[]{employee.getSsn()}, Locale.getDefault()));
              result.addError(ssnError);
              return "registration";
          }
  
          service.saveEmployee(employee);
  
          model.addAttribute("success", "Employee " + employee.getName() + " registered successfully");
          return "success";
      }
  
  
      /*
       * This method will provide the medium to update an existing employee.
       */
      @RequestMapping(value = { "/edit-{ssn}-employee" }, method = RequestMethod.GET)
      public String editEmployee(@PathVariable String ssn, ModelMap model) {
          Employee employee = service.findEmployeeBySsn(ssn);
          model.addAttribute("employee", employee);
          model.addAttribute("edit", true);
          return "registration";
      }
  
      /*
       * This method will be called on form submission, handling POST request for
       * updating employee in database. It also validates the user input
       */
      @RequestMapping(value = { "/edit-{ssn}-employee" }, method = RequestMethod.POST)
      public String updateEmployee(@Valid Employee employee, BindingResult result,
              ModelMap model, @PathVariable String ssn) {
  
          if (result.hasErrors()) {
              return "registration";
          }
  
          if(!service.isEmployeeSsnUnique(employee.getId(), employee.getSsn())){
              FieldError ssnError =new FieldError("employee","ssn",messageSource.getMessage("non.unique.ssn", new String[]{employee.getSsn()}, Locale.getDefault()));
              result.addError(ssnError);
              return "registration";
          }
  
          service.updateEmployee(employee);
  
          model.addAttribute("success", "Employee " + employee.getName()  + " updated successfully");
          return "success";
      }
  
  
      /*
       * This method will delete an employee by it's SSN value.
       */
      @RequestMapping(value = { "/delete-{ssn}-employee" }, method = RequestMethod.GET)
      public String deleteEmployee(@PathVariable String ssn) {
          service.deleteEmployeeBySsn(ssn);
          return "redirect:/list";
      }
  
  }
  </code></pre>
  
  <p>and this is application initializer</p>
  
  <pre><code>package org.dstech.examplespring.configuration;
  
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRegistration;
  
  import org.springframework.web.WebApplicationInitializer;
  import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
  import org.springframework.web.servlet.DispatcherServlet;
  
  /**
   * @author franksisca
   *
   */
  public class HelloWorldInit  implements WebApplicationInitializer{
  
      /* (non-Javadoc)
       * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext)
       */
      public void onStartup(ServletContext servletContext) throws ServletException {
          AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
          context.register(HelloWorldConfig.class);
          context.setServletContext(servletContext);
  
          ServletRegistration.Dynamic servlet = 
                  servletContext.addServlet
                  ("dispatcher", new DispatcherServlet(context));
          servlet.setLoadOnStartup(1);
          servlet.addMapping("/");
      }
  
  }
  </code></pre>
  
  <p>and last, but not least, my console error when i start tomcat</p>
  
  <pre><code>AVVERTENZA: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name
   'appController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.dstech.exam
  plespring.service.EmployeeService org.dstech.examplespring.controller.AppController.service; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No
   qualifying bean of type [org.dstech.examplespring.service.EmployeeService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency
  . Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  mag 18, 2016 6:09:29 PM org.springframework.web.servlet.DispatcherServlet initServletBean
  GRAVE: Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appController': Injection of autowired dependencies failed; nested exception is org.springfr
  amework.beans.factory.BeanCreationException: Could not autowire field: org.dstech.examplespring.service.EmployeeService org.dstech.examplespring.controller.AppController.service; n
  ested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.dstech.examplespring.service.EmployeeService] found for dependen
  cy: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=tr
  ue)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
      at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:666)
      at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:538)
      at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:492)
      at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      at javax.servlet.GenericServlet.init(GenericServlet.java:158)
      at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1090)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5231)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5518)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
      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:745)
  Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.dstech.examplespring.service.EmployeeService org.dstech.examplespring.controller.A
  ppController.service; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.dstech.examplespring.service.EmployeeServ
  ice] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotatio
  n.Autowired(required=true)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
      ... 26 more
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.dstech.examplespring.service.EmployeeService] found for dependency: expe
  cted at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
      ... 28 more
  </code></pre>
  
  <p>Can anyone help me? I think it's a problem with jade.time library, but i don't know how to solve. If I use java.util.Date i get the same error.</p>
  
  <hr>
  
  <p>EDIT</p>
  
  <p>Sorry, i forget my service</p>
  
  <pre><code>public interface EmployeeService {
  
      Employee findById(int id);
  
      void saveEmployee(Employee employee);
  
      void updateEmployee(Employee employee);
  
      void deleteEmployeeBySsn(String ssn);
  
      List&lt;Employee&gt; findAllEmployees(); 
  
      Employee findEmployeeBySsn(String ssn);
  
      boolean isEmployeeSsnUnique(Integer id, String ssn);
  
  }
  </code></pre>
  
  <p>and this is my implementation</p>
  
  <pre><code>@Service("employeeService")
  @Transactional
  public class EmployeeServiceImpl implements EmployeeService {
  
      @Autowired
      private EmployeeDao dao;
  
      public Employee findById(int id) {
          return dao.findById(id);
      }
  
      public void saveEmployee(Employee employee) {
          dao.saveEmployee(employee);
      }
  
      /*
       * Since the method is running with Transaction, No need to call hibernate update explicitly.
       * Just fetch the entity from db and update it with proper values within transaction.
       * It will be updated in db once transaction ends. 
       */
      public void updateEmployee(Employee employee) {
          Employee entity = dao.findById(employee.getId());
          if(entity!=null){
              entity.setName(employee.getName());
              entity.setJoiningDate(employee.getJoiningDate());
              entity.setSalary(employee.getSalary());
              entity.setSsn(employee.getSsn());
          }
      }
  
      public void deleteEmployeeBySsn(String ssn) {
          dao.deleteEmployee(ssn);
      }
  
      public List&lt;Employee&gt; findAllEmployees() {
          return dao.findAllEmployees();
      }
  
      public Employee findEmployeeBySsn(String ssn) {
          return dao.findEmployeeBySsn(ssn);
      }
  
      public boolean isEmployeeSsnUnique(Integer id, String ssn) {
          Employee employee = findEmployeeBySsn(ssn);
          return ( employee == null || ((id != null) &amp;&amp; (employee.getId() == id)));
      }
  
  }
  </code></pre>