13.07.2015 Views

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

please define productname in your docbook file!For example, to exclude certain interfaces from instantiation as repository, you could use the followingconfiguration:This example excludes all interfaces ending in SomeRepository from being instantiated.Example 4.6 Using exclude-filter elementJavaConfigThe repository infrastructure can also be triggered using a store-specific @Enable${store}Repositories annotation on a JavaConfig class. For an introduction into Java-basedconfiguration of the <strong>Spring</strong> container, see the reference documentation. 2A sample configuration to enable <strong>Spring</strong> <strong>Data</strong> repositories looks something like this.@Configuration@EnableJpaRepositories("com.acme.repositories")class ApplicationConfiguration {}@Beanpublic EntityManagerFactory entityManagerFactory() {// …}Example 4.7 Sample annotation based repository configurationNoteThe sample uses the JPA-specific annotation, which you would change according to the storemodule you actually use. The same applies to the definition of the EntityManagerFactorybean. Consult the sections covering the store-specific configuration.Standalone usageYou can also use the repository infrastructure outside of a <strong>Spring</strong> container. You still need some<strong>Spring</strong> libraries in your classpath, but generally you can set up repositories programmatically aswell. The <strong>Spring</strong> <strong>Data</strong> modules that provide repository support ship a persistence technology-specificRepositoryFactory that you can use as follows.RepositoryFactorySupport factory = … // Instantiate factory hereUserRepository repository = factory.getRepository(UserRepository.class);Example 4.8 Standalone usage of repository factory4.3 Custom implementations for <strong>Spring</strong> <strong>Data</strong> repositoriesOften it is necessary to provide a custom implementation for a few repository methods. <strong>Spring</strong> <strong>Data</strong>repositories easily allow you to provide custom repository code and integrate it with generic CRUDabstraction and query method functionality.2 JavaConfig in the <strong>Spring</strong> reference documentation - http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-java1.4.0.BUILD-SNAPSHOT<strong>Spring</strong> <strong>Data</strong> <strong>MongoDB</strong> -Reference Documentation 11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!