title: JpaRepository is null
body: <p>I am trying to connect database to my vaadin-app, using javaConfig. But my Layout does not get a JpaRepository injected.</p>
  
  <p><a href="https://i.stack.imgur.com/RV8bQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RV8bQ.png" alt="enter image description here"></a></p>
  
  <p>HotelCategoryServiceImpl.java</p>
  
  <pre><code>package com.gptravel.service.category;
  
  
  import com.gptravel.dao.HotelCategoryRepository;
  import com.gptravel.entity.HotelCategory;
  import com.gptravel.service.hotel.HotelServiceImpl;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  import java.util.List;
  import java.util.logging.Logger;    
  
  @Service("hotelCategoryService")
  @Transactional
  public class HotelCategoryServiceImpl implements HotelCategoryService {
  private static final Logger LOGGER = 
  Logger.getLogger(HotelServiceImpl.class.getName());
  
  @PersistenceContext
  private EntityManager em;
  
  @Autowired
  private HotelCategoryRepository hotelCategoryRepo;
  
  @Override
  public HotelCategory create(HotelCategory hotelCategory) {
      HotelCategory savehotelCategory = 
   hotelCategoryRepo.saveAndFlush(hotelCategory);
      return savehotelCategory;
  }
  
  @Override
  public void delete(long id) {
      hotelCategoryRepo.delete(id);
  
  }
  
  @Override
  public HotelCategory getById(long id) {
      return hotelCategoryRepo.findOne(id);
  }
  
  @Override
  public HotelCategory update(HotelCategory hotelCategory) {
      return hotelCategoryRepo.saveAndFlush(hotelCategory);
  }
  
  //get all categories
  @Override
  @Transactional(readOnly = true)
  public  List&lt;HotelCategory&gt; findAll() {
      return hotelCategoryRepo.findAll();
  }
  }
  </code></pre>
  
  <p>HotelCategoryService.java</p>
  
  <pre><code>package com.gptravel.service.category;
  
  
  import com.gptravel.entity.HotelCategory;
  import org.springframework.stereotype.Service;
  
  import java.util.List;
  
  @Service("hotelCategoryService")
  public interface HotelCategoryService {
  
  HotelCategory create(HotelCategory hotelCategory);
  void delete(long id);
  HotelCategory getById(long id);
  HotelCategory update(HotelCategory hotelCategory);
  List&lt;HotelCategory&gt; findAll();
  }
  </code></pre>
  
  <p>Repository:</p>
  
  <pre><code>import com.gptravel.entity.HotelCategory;
  import org.springframework.data.domain.Pageable;
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.stereotype.Repository;
  
  import java.util.List;
  
  @Repository
  public interface HotelCategoryRepository extends 
  JpaRepository&lt;HotelCategory, Long&gt; {
  
  List&lt;HotelCategory&gt; findAllBy(Pageable pageable);
  }
  </code></pre>
  
  <p>Jpa Config.java</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @ComponentScan("com.gptravel")
  @PropertySource(value = { "classpath:application.properties" })
  @EnableJpaRepositories(basePackages="com.gptravel.dao")
  public class HibernateConfig {
  
  @Resource
  private Environment environment;
  
  @Bean
  public DataSource dataSource() {
      DriverManagerDataSource dataSource = new DriverManagerDataSource();
      dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
      dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
      dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
      dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
      return dataSource;
  }
  
  @Bean
  public EntityManagerFactory entityManagerFactory() throws NamingException {
      HibernateJpaVendorAdapter vendorAdapter = new 
      HibernateJpaVendorAdapter();
      vendorAdapter.setGenerateDdl(true);
  
      LocalContainerEntityManagerFactoryBean factoryBean = new 
      LocalContainerEntityManagerFactoryBean();
      factoryBean.setJpaVendorAdapter(vendorAdapter);
      factoryBean.setPackagesToScan("com.gptravel.entity");
      factoryBean.setDataSource(dataSource());
  
      factoryBean.setPersistenceProviderClass
      (HibernatePersistenceProvider.class);
      factoryBean.setJpaProperties(jpaProperties());
      factoryBean.setPersistenceUnitName("demo_hotels");
      factoryBean.afterPropertiesSet();
      return factoryBean.getObject();
  }
  
  private Properties jpaProperties() {
      Properties properties = new Properties();
      properties.put("hibernate.dialect", 
  environment.getRequiredProperty("hibernate.dialect"));
      properties.put("hibernate.show_sql", 
  environment.getRequiredProperty("hibernate.show_sql"));
      properties.put("hibernate.hbm2ddl.auto", 
  environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
      return properties;
  }
  
  @Bean
  public PlatformTransactionManager transactionManager() throws 
  NamingException {
      JpaTransactionManager txManager = new JpaTransactionManager();
      txManager.setEntityManagerFactory(entityManagerFactory());
      return txManager;
  }
  
  @Bean
  public SpringLiquibase liquibase() {
      SpringLiquibase liquibase = new SpringLiquibase();
      liquibase.setChangeLog("classpath:db/db.changelog.xml");
      liquibase.setDataSource(dataSource());
      return liquibase;
  }
  }
  </code></pre>
  
  <p>My app have simple test connect to database, which ends successfully
  TestJpaConfig.java</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @ComponentScan("com.gptravel")
  public class TestDataBaseConfig {
  
  private static final String PROPERTY_NAME_DATABASE_DRIVER = "com.mysql.jdbc.Driver";
  private static final String PROPERTY_NAME_DATABASE_URL = "jdbc:mysql://localhost:3306/demo_hotels";
  private static final String PROPERTY_NAME_DATABASE_USERNAME = "demo";
  private static final String PROPERTY_NAME_DATABASE_PASSWORD = "demo";
  
  private static final String PROPERTY_NAME_HIBERNATE_DIALECT = "org.hibernate.dialect.MySQLDialect";
  private static final String PROPERTY_NAME_HIBERNATE_SHOW_SQL = "true";
  private static final String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN = "com.gptravel.entity";
  private static final String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO = "update";
  
  @Bean
  public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
      LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
      entityManagerFactoryBean.setDataSource(dataSource());
      entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistence.class);
      entityManagerFactoryBean.setPackagesToScan(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN);
  
      entityManagerFactoryBean.setJpaProperties(hibernateProp());
  
      return entityManagerFactoryBean;
  }
  
  @Bean
  public JpaTransactionManager transactionManager() {
      JpaTransactionManager transactionManager = new JpaTransactionManager();
      transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
  
      return transactionManager;
  }
  
  @Bean
  public DataSource dataSource() {
      DriverManagerDataSource dataSource = new DriverManagerDataSource();
  
      dataSource.setDriverClassName(PROPERTY_NAME_DATABASE_DRIVER);
      dataSource.setUrl(PROPERTY_NAME_DATABASE_URL);
      dataSource.setUsername(PROPERTY_NAME_DATABASE_USERNAME);
      dataSource.setPassword(PROPERTY_NAME_DATABASE_PASSWORD);
  
      return dataSource;
  }
  
  private Properties hibernateProp() {
      Properties properties = new Properties();
      properties.put("hibernate.dialect", PROPERTY_NAME_HIBERNATE_DIALECT);
      properties.put("hibernate.show_sql", PROPERTY_NAME_HIBERNATE_SHOW_SQL);
      properties.put("hibernate.hbm2ddl.auto", PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO);
      return properties;
  }
  
  }
  </code></pre>
  
  <p>TestClass.java</p>
  
  <pre><code>@DirtiesContext
  @RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = TestDataBaseConfig.class)
  @WebAppConfiguration
  public class HotelServiceImplTest {
  @Resource
  private EntityManagerFactory emf;
  protected EntityManager em;
  
  @Resource
  private HotelRepository hotelCategoryService;
  
  @Before
  public void setUp() throws Exception {
  em = emf.createEntityManager();
  }
  
  @Test
  public void testSaveHotelCategory() throws Exception {
  hotelCategoryService.findAll();
  List&lt;Hotel&gt; testList = hotelCategoryService.findAll();
  System.out.println("Size - " + testList.size());
  
  
  }
  
  }
  </code></pre>
  
  <p>What could be the problem?</p>
  
  <p><strong>UPDATE #1</strong></p>
  
  <p>I added annotation like <code>@Service</code>, <code>@Component</code> but app still doesn't work.</p>
  
  <p>Link to my repo: <a href="https://bitbucket.org/dmitriu_p/gptravel" rel="nofollow noreferrer">VaadinJPAHotelApp</a></p>