Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boot-strapping Spring Data JPA without XML

What is the Java @Configuration equivalent to:

<repositories base-package="com.acme.repositories" />

in Spring Data JPA? I am trying to get rid of XML configuration in favour to @Configuration classes, however reading through JpaRepositoryConfigDefinitionParser sources is fruitless.

The closest what I can get is:

@Bean
public RepositoryFactorySupport repositoryFactory() {
    return new JpaRepositoryFactory(entityManagerFactory().createEntityManager())
}

@Bean
public BookDao bookDao() {
    return repositoryFactory().getRepository(BookDao.class)
}

However the <repositories/> tag is much more functional: it automatically creates DAO for all interfaces extending CrudRepository found on CLASSPATH. Also it seems like my solution does not apply transactions to DAOs as opposed to default Spring Data JPA behaviour.

like image 647
Tomasz Nurkiewicz Avatar asked Oct 31 '11 22:10

Tomasz Nurkiewicz


1 Answers

Spring Data JPA introduced @EnableJpaRepositories. See the reference documentation for details.

like image 175
Oliver Drotbohm Avatar answered Sep 20 '22 15:09

Oliver Drotbohm