Giter Site home page Giter Site logo

spring-data-multiple-namespaces-example's Introduction

Spring Data Aerospike: Multiple Namespaces Example

The goal of this example is to demonstrate how to use multiple namespaces with Spring Data Aerospike.

Using a single namespace with Spring Data Aerospike is pretty straight forward, Configuration comes out-of-the-box, all you need to do is to extend AbstractAerospikeDataConfiguration class and override two methods: getHosts() and nameSpace(). You can see an example of using a single namespace in Simple Web Application Using Java, Spring Boot, Aerospike and Docker .

Using multiple namespaces with Spring Data Aerospike requires a bit of additional code. Create a configuration class per namespace, and in each configuration class do the following:

  • extend AbstractAerospikeDataConfiguration
  • override both getHosts() and nameSpace()
  • create an AerospikeTemplate bean (with unique bean name and method name)
  • point the aerospikeTemplateRef property of the @EnableAerospikeRepositories annotation to the name of the newly created AerospikeTemplate bean.

You can see a fully working example in this repository.

Version

The Spring Data Aerospike versions that support multiple namespaces are 3.1.0 and above. Try to use the latest version whenever possible.

<dependency>
    <groupId>com.aerospike</groupId>
    <artifactId>spring-data-aerospike</artifactId>
    <version>4.8.0</version>
</dependency>

Multiple repositories in a package

If both repositories are located in the same package - same as in this example (AerospikeProductsRepository and AerospikeUsersRepository are both part of the repositories package), then you need to use the includeFilters field of the @EnableAerospikeRepositories annotation on your configuration class pointing to the relevant repository using customized annotations (ProductsRepository and UsersRepository).

Upgrading to Spring 3

Please note that after upgrading to Spring 3 each of multiple AerospikeTemplate beans must contain method with a unique name which should not be called "aerospikeTemplate". Here is a simple example of a correct bean:

@Bean(name = "aerospikeTemplateUsers")
public AerospikeTemplate aerospikeTemplateUsers(

spring-data-multiple-namespaces-example's People

Contributors

roimenashe avatar agrgr avatar

Stargazers

Aviral Agarwal avatar Zohar Elkayam avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.