title: Two session Factories found when one was expected
body: <p>I have referred to the question asked at <a href="https://stackoverflow.com/questions/5843953/hibernate-using-multiple-databases">Hibernate using multiple databases</a>. My problem is similar but I am facing a different problem.I created two xml file each has a separate datasource and session factory.
  In my web.xml I have </p>
  
  <pre><code> &lt;context-param&gt;
   &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
       &lt;param-value&gt;*The xml files* &lt;/param-value&gt;
  </code></pre>
  
  <p>Once I run the project,the various loadings and the bindings are done from both the xml files.The various annotations and databases/tables are properly identified.But just after this is done before the control even goes outside.I get the following error.   </p>
  
  <pre><code>    main ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed  
      org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'daoEager' defined in URL [jar:file:/C:/Users/.../.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/infobutton-service/WEB-INF/lib/core-data-1.0.0-SNAPSHOT.jar!/.../DaoHibernateEagerImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : No unique bean of type [org.hibernate.SessionFactory] is defined: expected single matching bean but found 2: [sessionFactory, profilesessionFactory]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.hibernate.SessionFactory] is defined: expected single matching bean but found 2: [sessionFactory, profilesessionFactory]
  </code></pre>
  
  <p>The class DaoHibernateEagerImpl is </p>
  
  <pre><code>@Implementation
  @Repository("daoEager")
  public class DaoHibernateEagerImpl extends DaoHibernateImpl
  {
  // ========================= CONSTANTS =================================
  
  /**
   * A logger that helps identify this class' printouts.
   */
  private static final Logger log = getLogger(DaoHibernateEagerImpl.class);
  
  // ========================= CONSTRUCTORS ==============================
  
  /**
   * Required for a Spring DAO bean.
   *
   * @param sessionFactory
   *            Hibernate session factory
   */
  @Autowired
  public DaoHibernateEagerImpl(final SessionFactory sessionFactory)
  {
      super(sessionFactory);
  }
  
  // ========================= DEPENDENCIES ==============================
  
  // ========================= IMPLEMENTATION: Dao =======================
  
  
  
  // ========================= IMPLEMENTATION: SearchEngine ==============
  
  
  }
  </code></pre>
  
  <p>One of the xml files is </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:aop="http://www.springframework.org/schema/aop"     
      xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:jee="http://www.springframework.org/schema/jee"
  xmlns:jaxws="http://cxf.apache.org/jaxws"
  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/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
  http://www.springframework.org/schema/jee
  http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
  http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"&gt;
  
      &lt;context:annotation-config /&gt;
  
  &lt;!--
      Data source: reads a properties file and injects them into a DBCP DS
      Second datasource for Resource Profiles
  --&gt;
  &lt;bean id="profiledataSource"
      class=".....ConfigurableBasicDataSource"&gt;
      &lt;constructor-arg index="0"&gt;
          &lt;bean class="org.apache.commons.dbcp.BasicDataSource" /&gt;
      &lt;/constructor-arg&gt;
      &lt;property name="properties"&gt;
          &lt;bean
  
      class="org.springframework.beans.factory.config.PropertiesFactoryBean"&gt;
              &lt;property name="locations"&gt;
                  &lt;list&gt;
                      &lt;value&gt;WEB-INF/datasource-local.properties
                      &lt;/value&gt;
                  &lt;/list&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  
      &lt;!-- FUR-946: idle connections break. Adding connection testing. --&gt;
      &lt;property name="testOnBorrow" value="true" /&gt;
      &lt;property name="testWhileIdle" value="true" /&gt;
  &lt;/bean&gt;
  
  
  
  
      &lt;!-- Session factory --&gt;
  &lt;!-- Session Factory for the second datasource--&gt;
  &lt;bean id="profilesessionFactory"
  
  
     class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="profiledataSource" /&gt;
  
      &lt;!--
          Hibernate configuration properties (read from a properties file)
      --&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;bean
  
      class="org.springframework.beans.factory.config.PropertiesFactoryBean"&gt;
              &lt;property name="locations"&gt;
                  &lt;list&gt;
                      &lt;value&gt;WEB-INF/hibernate.properties
                      &lt;/value&gt;
                      &lt;value&gt;WEB-INF/datasource-local.properties
                      &lt;/value&gt;
  
                  &lt;/list&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  
      &lt;!-- Using improved naming strategy --&gt;
      &lt;property name="namingStrategy"&gt;
          &lt;bean class="org.hibernate.cfg.DefaultNamingStrategy" /&gt;
      &lt;/property&gt;
  
  
  
  
      &lt;!-- Mapping annotated classes using search patterns --&gt;
      &lt;property name="annotatedClasses"&gt;
          &lt;list&gt;
              &lt;value&gt;&lt;![CDATA[....profiledb.domain.Profiles]]&gt;&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
   &lt;!--   Hibernate data access template --&gt;
   &lt;bean id="profilehibernateTemplate"      
    class="org.springframework.orm.hibernate3.HibernateTemplate"&gt;
  
    &lt;property name="sessionFactory" ref="profilesessionFactory" /&gt;
  &lt;/bean&gt;
  
  
  &lt;tx:annotation-driven /&gt;
  
  &lt;!-- a PlatformTransactionManager is still required --&gt;
  &lt;bean id="profiletransactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="profilesessionFactory" /&gt;
  &lt;/bean&gt;
  
  
  &lt;bean id="profilesdbDao" class="....profiledb.service.ProfilesDaoImpl" &gt;
      &lt;property name="sessionFactory" ref="profilesessionFactory"&gt;&lt;/property&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;context:component-scan base-package="....core.data" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>The other xml file is similar but has a different datasource and the session factory is </p>
  
  <pre><code>&lt;bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
   .....
  </code></pre>