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()
andnameSpace()
- 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 createdAerospikeTemplate
bean.
You can see a fully working example in this repository.
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>
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
).
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(