title: How to connect Two Database MySQL and MongoDB in the same project? Is it possible?
body: <p>Currently I'm using Hibernate(MySQL) with Spring, the configuration is running fine for me, but once I configured another configuration mongo-config.xml file and trying to run a test case with mongodb it's <strong>showing Error creating bean with name ....</strong> from first configuration.</p>
  
  <p><strong>Below is my mongo-config.xml</strong></p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="com.test.mongo" /&gt;
  &lt;context:property-placeholder location="classpath:mongo-dao.properties" /&gt;
  
  &lt;bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"&gt;
      &lt;constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /&gt;
  
  &lt;/bean&gt;
  &lt;bean id="mongoDbFactory" class="org.springframework.data.mongodb.core.MongoFactoryBean"&gt;
      &lt;property name="driverClassName" value="${spring.datasource.driverClassName}" /&gt;
      &lt;property name="host" value="${spring.data.mongodb.host}" /&gt;
      &lt;property name="port" value="${spring.data.mongodb.port}" /&gt;
      &lt;property name="databaseName" value="${spring.data.mongodb.database}" /&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>and my first configuration for hibernate is looks like something</strong> </p>
  
  <p></p>
  
  <pre><code>&lt;context:component-scan base-package="com.hb.dao" /&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
  &lt;bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="${db.jdbc.driverClassName}" /&gt;
      &lt;property name="url" value="${db.jdbc.url}" /&gt;
      &lt;property name="username" value="${db.jdbc.username}" /&gt;
      &lt;property name="password" value="${db.jdbc.password}" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sessionFactory"
      class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="packagesToScan"&gt;
          &lt;list&gt;
              &lt;value&gt;com.hb..dao.domain.entity&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql:false}&lt;/prop&gt;
              &lt;prop key="hibernate.format_sql"&gt;${hibernate.format_sql:false}&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&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><strong>And the stack trace is</strong></p>
  
  <pre><code>java.lang.IllegalStateException: Failed to load ApplicationContext
  at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
  at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
  at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
  at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
  at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:331)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  </code></pre>
  
  <p><strong><em>Caused by:  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accessProfileDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.soe.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.</em></strong> 
  Dependency annotations: </p>
  
  <p><strong>Here is my test Class-</strong></p>
  
  <pre><code>    public class MongoQuestionsTest extends BaseDaoMongoTest{   
          private static final Logger logger = LogManager.getLogger(MongoQuestionsTest.class);
  
          @Autowired
          private MongoTestDao mongoTestDaoImpl;
          @Test
          public void saveQuestions(){
              MongoQuestions mongoQuestions = new MongoQuestions();
              mongoQuestions.setUsername("Hi");
              mongoQuestions.setPassword("Hello");
              mongoTestDaoImpl.save(mongoQuestions);
              logger.debug("Mongo User Set with id " + mongoQuestions.getId());
          }
      and **BaseDaoMongoTest**---
  
      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration(locations={"classpath:/mongo-config-test.xml"})
      public class BaseDaoMongoTest {
      }
  </code></pre>
  
  <p>And in MongoTestDaoImpl class I just Auto-wired MongoTemplate and calling save() method that's it.</p>