title: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:
body: <p>I am trying  to use multiple datasource from a springboot application using Spring data jpa repository and  to call the repository method in a spring rest controller/service, wan not able to call repository method. Please find my classes below and suggest appropriate solution.</p>
  
  <pre class="lang-java prettyprint-override"><code>// define the service layer to call the repository
  public TestService{
      @Autowired
      private xyRepository xyzRepo;
  // Not able to autowire the 
  
  xyzRepo.findAll();
  
  //REpository class
  
  public interface xyRepository extends PagingAndSortingRepository&lt;SiteEntity,String&gt;{
  
  {
      //call the API method
  }
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>/***Application.properties***/
  
  #production DataBase
  spring.datasource.driver-class-name= com.microsoft.sqlserver.jdbc.SQLServerDriver
  spring.datasource.url = jdbc:sqlserver://cdef.com:1435;DatabaseName=tttt
  spring.datasource.username = reader
  spring.datasource.password = xxxxxxxx
  
  
  #production DataBase for PGSEO DB
  spring.abcdatasource.driver-class-name= com.microsoft.sqlserver.jdbc.SQLServerDriver
  spring.abcdatasource.url = jdbc:sqlserver://xyz.com:1436;DatabaseName=abc
  spring.abcdatasource.username = xyz
  spring.abcdatasource.password = xxxxxx
  
  
  #spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
  
  
  # Keep the connection alive if idle for a long time (needed in production)
  spring.datasource.testWhileIdle = true
  spring.datasource.validationQuery = SELECT 1
  
  # Show or not log for each sql query
  spring.jpa.show-sql = false
  
  server.port = 9595
  
  # Naming strategy
  
  # Use spring.jpa.properties.* for Hibernate native properties (the prefix is
  # stripped before adding them to the entity manager)
  
  # The SQL dialect makes Hibernate generate better SQL for the chosen database
  spring.jpa.hibernate.naming.strategy = org.hibernate.cfg.ImprovedNamingStrategy
  #spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
  spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.SQLServerDialect
  spring.datasource.initialize=false
  spring.jpa.hibernate.ddl-auto=false
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>//1st java config file
  
  package com.sample;
  
  import java.io.IOException;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Properties;
  import java.util.stream.Collectors;
  
  import javax.persistence.EntityManagerFactory;
  import javax.sql.DataSource;
  
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
  import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Primary;
  import org.springframework.core.io.ClassPathResource;
  import org.springframework.core.io.Resource;
  import org.springframework.core.io.support.PropertiesLoaderUtils;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.orm.jpa.JpaTransactionManager;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.transaction.PlatformTransactionManager;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  
  @Configuration
  @EnableTransactionManagement
  @EnableJpaRepositories(
          entityManagerFactoryRef = "eoianalyticEntityManager", 
          transactionManagerRef = "eoianalyticTransactionManager", 
          basePackages = "com.sample.jparepository.primary" /*** Give the JPA repository location for eoi analytic DB**/
  )
  public class EOIAnalyticConfig {
      @Bean
      @Primary
      @ConfigurationProperties(prefix = "spring.datasource")
      public DataSource springDataSource() {
          return DataSourceBuilder
                      .create()
                      .build();
      }
      /**
       * Entity manager definition. 
       *  
       * @param builder an EntityManagerFactoryBuilder.
       * @return LocalContainerEntityManagerFactoryBean.
       */
      @Primary
      @Bean(name = "eoianalyticEntityManager")
      public LocalContainerEntityManagerFactoryBean eoianalyticEntityManagerFactory(EntityManagerFactoryBuilder builder) {
          return builder
                      .dataSource(springDataSource())
                      .properties(hibernateProperties())
                      .packages("com.sample.entity.primary")
                      .persistenceUnit("eoianalyticpu")
                      .build();
      }
  
      @Primary
      @Bean(name = "eoianalyticTransactionManager")
      public PlatformTransactionManager eoianalyticTransactionManager(@Qualifier("eoianalyticEntityManager") EntityManagerFactory entityManagerFactory) {
          return new JpaTransactionManager(entityManagerFactory);
      }
      private Map&lt;String, Object&gt; hibernateProperties() {
  
          Resource resource = new ClassPathResource("application.properties");
  
          try {
              Properties properties = PropertiesLoaderUtils.loadProperties(resource);
              return properties.entrySet().stream()
                                              .collect(Collectors.toMap(
                                                          e -&gt; e.getKey().toString(),
                                                          e -&gt; e.getValue())
                                                      );
          } catch (IOException e) {
              return new HashMap&lt;String, Object&gt;();
          }
      }
  
  }
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>//2nd config file for second datasource
  
  package com.sample;
  
  import java.io.IOException;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Properties;
  import java.util.stream.Collectors;
  
  import javax.persistence.EntityManagerFactory;
  import javax.sql.DataSource;
  
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
  import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.core.io.ClassPathResource;
  import org.springframework.core.io.Resource;
  import org.springframework.core.io.support.PropertiesLoaderUtils;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.orm.jpa.JpaTransactionManager;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.transaction.PlatformTransactionManager;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  
  @Configuration
  @EnableTransactionManagement
  @EnableJpaRepositories(
          entityManagerFactoryRef = "abcEntityManager", 
          transactionManagerRef = "pgseoTransactionManager", 
          basePackages = "com.sample.jparepository.secondary"/**** Provide the secondary repository package name*******/
  )
  public class PGSEOConfig {
          /**
           * PGSEO datasource definition.
           * 
           * @return datasource.
           */
          @Bean
          @ConfigurationProperties(prefix = "spring.abcdatasource")
          public DataSource pgseoDataSource() {
              return DataSourceBuilder
                          .create()
                          .build();
          }
          /**
           * Entity manager definition. 
           *  
           * @param builder an EntityManagerFactoryBuilder.
           * @return LocalContainerEntityManagerFactoryBean.
           */
          @Bean(name = "pgseoEntityManager")
          public LocalContainerEntityManagerFactoryBean pgseoEntityManagerFactory(EntityManagerFactoryBuilder builder) {
              return builder
                          .dataSource(pgseoDataSource())
                          .properties(hibernateProperties())
                          .packages("com.sample.entity.secondary")
                          .persistenceUnit("pgseoPU")
                          .build();
          }
          /**
           * @param entityManagerFactory
           * @return
           */
          @Bean(name = "pgseoTransactionManager")
          public PlatformTransactionManager pgseoTransactionManager(@Qualifier("pgseoEntityManager") EntityManagerFactory entityManagerFactory) {
              return new JpaTransactionManager(entityManagerFactory);
          }
          private Map&lt;String, Object&gt; hibernateProperties() {
  
              Resource resource = new ClassPathResource("config/"+"application.properties");
              try {
                  Properties properties = PropertiesLoaderUtils.loadProperties(resource);
                  return properties.entrySet().stream()
                                                  .collect(Collectors.toMap(
                                                              e -&gt; e.getKey().toString(),
                                                              e -&gt; e.getValue())
                                                          );
              } catch (IOException e) {
                  return new HashMap&lt;String, Object&gt;();
              }
          }
  
  }
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>---------------------------------------------------------
  //POM.xml file 
  
  package com.sample;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.boot.autoconfigure.domain.EntityScan;
  import org.springframework.context.annotation.ComponentScan;
  
  @SpringBootApplication
  @ComponentScan(basePackages=("com.sample.*"))
  @EntityScan(basePackages = ("com.sample.entity.*"))
  @EnableAutoConfiguration
  public class MultipleDataSourceApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(MultipleDataSourceApplication.class, args);
      }
  }
  </code></pre>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &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;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;demo&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;MultipleDataSource&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.5.3.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
            &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-configuration-processor&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.microsoft.sqlserver&lt;/groupId&gt;
              &lt;artifactId&gt;sqljdbc4&lt;/artifactId&gt;
              &lt;version&gt;4-4.0&lt;/version&gt;  
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>