title: Getting error : Unknown service requested [org.hibernate.boot.registry.classloading.spi.ClassLoaderService]
body: <p>I'm using Spring 3.2.3.RELEASE + Hibernate 4.3.5.Final and I cannot start my application (on tomcat 6)</p>
  
  <p>Error:</p>
  
  <pre><code>SEVERE: Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.boot.registry.classloading.spi.ClassLoaderService]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:608)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
      at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1276)
      at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:625)
      at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:136)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:194)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      at java.lang.Thread.run(Thread.java:744)
  Caused by: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.boot.registry.classloading.spi.ClassLoaderService]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:125)
      at org.hibernate.envers.event.spi.EnversIntegrator.integrate(EnversIntegrator.java:76)
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:307)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1797)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1868)
      at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247)
      at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373)
      at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
      ... 35 more
  </code></pre>
  
  <p>applicationContext : </p>
  
  <pre><code>&lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
    &lt;property name="dataSource" ref="dataSource" /&gt;
    &lt;property name="configLocation"&gt;
      &lt;value&gt;classpath:hibernate.cfg.xml&lt;/value&gt;
    &lt;/property&gt;
    &lt;property name="hibernateProperties"&gt;
      &lt;props&gt;
        &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/prop&gt;
        &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
        &lt;prop key="hbm2ddl.auto"&gt;update&lt;/prop&gt;
      &lt;/props&gt;
    &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
    &lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
    &lt;property name="url" value="jdbc:postgresql://localhost:5432/springapp" /&gt;
    &lt;property name="username" value="hibernate" /&gt;
    &lt;property name="password" value="hib" /&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
    &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>One entity:</p>
  
  <pre><code>import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.ManyToOne;
  import javax.persistence.Table;
  
  import springapp.service.NewRecipe;
  
  import com.google.common.base.Strings;
  
  
  @Entity
  @Table
  public class Recipe {
  
      public static final String D_ID = "id";
      public static final String D_NAME = "name";
      public static final String D_DESCRIPTION = "description";
  
      @Id @GeneratedValue @Column(name = D_ID) private long id;
      @Column(nullable = false, unique = true, name = D_NAME) private String name;
      @Column(nullable = false, name = D_DESCRIPTION) private String description;
      @ManyToOne(optional = false) private Category category;
  
  
      public Recipe() {
          // for ORM
      }
  }
  </code></pre>
  
  <p>One dao:</p>
  
  <pre><code>import java.util.List;
  
  import org.hibernate.Criteria;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.criterion.Property;
  import org.hibernate.criterion.Restrictions;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Repository;
  
  import springapp.domain.Recipe;
  import springapp.service.NewRecipe;
  
  
  @Repository("recipeDao")
  public class HibernateRecipeDao implements RecipeDao {
  
      @Autowired private SessionFactory sessionFactory;
  
  
      @Override
      public List&lt;Recipe&gt; getRecipes() {
          final Session session = sessionFactory.getCurrentSession();
  
          final Criteria criteria = session.createCriteria(Recipe.class).addOrder(Property.forName(Recipe.D_ID).asc());
          final List&lt;Recipe&gt; recipes = criteria.list();
  
          return recipes;
      }
  }
  </code></pre>
  
  <p>One manager : </p>
  
  <pre><code>import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  import springapp.domain.Recipe;
  import springapp.repository.RecipeDao;
  
  
  @Service("recipeManager")
  public class HibernateRecipeManager implements RecipeManager {
  
      @Autowired private RecipeDao recipeDao;
  
  
      @Transactional
      @Override
      public List&lt;Recipe&gt; getRecipes() {
          return recipeDao.getRecipes();
      }
  }
  </code></pre>