title: NoSuchBeanDefinitionException: No qualifying bean of type is defined
body: <p>i have spring mvc+jpa project. When I run this project and go to <code>/service</code> link i get excepiton. I'm try work with <code>@Autowired</code> but i get another exception, because use <code>applicationContext</code></p>
  
  <pre><code>HTTP Status 500 - Request processing failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.ua.korbo.persistence.repository.PupilRepository] is defined
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>@Controller
  public class WebController {
  
      private PupilService pupilService;
      private PupilRepository pupilRepository;
      private ApplicationContext context;
  
      private void setUpField(){
          System.out.println("1");
          if (context == null){
              System.out.println("2");
              context = new AnnotationConfigApplicationContext(BeanClass.class);
              System.out.println("3");
          }
          System.out.println("4");
          if (pupilService == null){
              System.out.println("5");
              pupilService = context.getBean(PupilServiceImpl.class);
              System.out.println("6");
          }
          System.out.println("7");
          if (pupilRepository == null){
              System.out.println("8");
              System.out.printf(pupilRepository + " start");
              pupilRepository = context.getBean(PupilRepository.class);
              System.out.printf(pupilRepository+" end");
              System.out.println("9");
          }
      }    
  @RequestMapping(value = "/service", method = RequestMethod.GET)
      public String printService(Map&lt;String, String&gt; model){
          setUpField();
          pupilService.findAll();
          pupilService.setPupilRepositories(pupilRepository);
          pupilService.save(new Pupil("Name", "Last", "Email", "MSG", "Number"));
          model.put("key", "This is service!");
          return "print";
      }
  }
  </code></pre>
  
  <p>Information from sout <code>setUpField</code></p>
  
  <pre><code>1
  2
  08-Sep-2015 21:30:42.871 INFO [http-nio-8080-exec-7] org.hibernate.jpa.internal.util.LogHelper.logPersistenceUnitInformation HHH000204: Processing PersistenceUnitInfo [
      name: default
      ...]
  08-Sep-2015 21:30:42.902 INFO [http-nio-8080-exec-7] org.hibernate.dialect.Dialect.&lt;init&gt; HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
  08-Sep-2015 21:30:43.048 INFO [http-nio-8080-exec-7] &lt;unknown&gt;.&lt;unknown&gt; HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
  08-Sep-2015 21:30:43.048 INFO [http-nio-8080-exec-7] &lt;unknown&gt;.&lt;unknown&gt; HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@229bbfd5
  08-Sep-2015 21:30:43.055 INFO [http-nio-8080-exec-7] &lt;unknown&gt;.&lt;unknown&gt; HHH000228: Running hbm2ddl schema update
  08-Sep-2015 21:30:43.066 WARN [http-nio-8080-exec-7] org.hibernate.jpa.internal.EntityManagerFactoryRegistry.addEntityManagerFactory HHH000436: Entity manager factory name (default) is already registered.  If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
  3
  4
  5
  6
  7
  8
  null start
  </code></pre>
  
  <p><strong>Web Initializer</strong></p>
  
  <pre><code>public class MyWebInitializer extends
          AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class[] { SpringRootConfig.class, PersistenceContext.class};
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return new Class[] { SpringWebConfig.class };
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[] { "/" };
      }
  }
  </code></pre>
  
  <p><strong>Persistance context</strong></p>
  
  <pre><code>@Configuration
  @EnableJpaRepositories(basePackages = {"persistence.repository"},
          entityManagerFactoryRef = "entityManagerFactory",
          transactionManagerRef = "transactionManager")
  @EnableTransactionManagement
  @PropertySource("classpath:app.properties")
  public class PersistenceContext {
  
      public PersistenceContext() {
      }
  
      /**
       * The method that configures the datasource bean
       * */
  
      @Resource
      private Environment env;
  
      @Bean
      DataSource dataSource() {
          HikariConfig dataSourceConfig = new HikariConfig();
          dataSourceConfig.setJdbcUrl(env.getRequiredProperty("db.url"));
          dataSourceConfig.setDriverClassName(env.getRequiredProperty("db.driver"));
          dataSourceConfig.setUsername(env.getRequiredProperty("db.username"));
          dataSourceConfig.setPassword(env.getRequiredProperty("db.password"));
  
          return new HikariDataSource(dataSourceConfig);
      }
  
      /**
       * The method that configures the entity manager factory
       * */
      @Bean
      LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, Environment env) {
          LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
          entityManagerFactoryBean.setDataSource(dataSource);
          entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
          entityManagerFactoryBean.setPackagesToScan("entity");
  
          Properties jpaProperties = new Properties();
  
          jpaProperties.put("hibernate.dialect", env.getRequiredProperty("hibernate.dialect"));
          jpaProperties.put("hibernate.hbm2ddl.auto", env.getRequiredProperty("hibernate.hbm2ddl.auto"));
          jpaProperties.put("hibernate.show_sql", env.getRequiredProperty("hibernate.show_sql"));
          jpaProperties.put("hibernate.format_sql", env.getRequiredProperty("hibernate.format_sql"));
  
          entityManagerFactoryBean.setJpaProperties(jpaProperties);
  
          return entityManagerFactoryBean;
      }
  
      /**
       * The method that configures the transaction manager
       * */
      @Bean
      JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
          JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(entityManagerFactory);
          return transactionManager;
      }
  }
  </code></pre>
  
  <p><strong>Repository</strong></p>
  
  <pre><code>@Repository
  public interface PupilRepository extends CrudRepository&lt;Pupil, Long&gt; {
  }
  </code></pre>