How to use Aerospike in Spring framework like MongoDB

Hi, I am trying to use Aerospike in Spring framework just like MongoDB. I have gone through the official website and get these guides:

http://www.aerospike.com/docs/connectors/spring/

I found that you guys have used these pom dependencies:

<dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-aerospike</artifactId>
      <version>1.5.0.RELEASE</version>
    </dependency>

<dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-data-aerospike</artifactId>
         <version>0.0.1-SNAPSHOT</version>
 </dependency> 

I have found these dependencies in http://mvnrepository.com but could not find them valid. I need to implement spring based dependency in Gradle. Please guide me with valid dependency in Gradle, so that I can access aerospike in Spring framework.

I can access mongodb like : import org.springframework.data.mongodb. but could not able to get : import org.springframework.data.aerospike. (as mentioned in your docs and Git).

NOTE: I have used the above dependencies in my gradle project also and my gradle could not compile. It seems these are not valid maven repositories.

Hi Hafsa,

Spring Data for Aerospike is a Spring Community project controlled by Pivotal (Spring) and sponsored by Aerospike.

Currently there is an issue with the automated build of Spring Data for Aerospike preventing the JAR to be published in Maven Central, and Aerospike has raised these with Pivotal.

In the mean time, I recommend that you clone the GitHub repo and build it.

This build command will build, test and install it in your local Maven repo.

mvn clean install

I hope this helps

Peter

Thank you for your reply. It works for me, but I am getting one more issue related to Aerospike Template. Note: I am using gradle in spring framework.

I have this bean in my configuration:

    public @Bean  AerospikeClient aerospikeClient() {
        return new AerospikeClient(this.aerospikeHost(), this.aerospikePort());
    }


    public @Bean AerospikeTemplate aerospikeTemplate() throws Exception {
        return new AerospikeTemplate(aerospikeClient(), "myNamespaceName");
    }

If I Autowire aerospikeClient, It goes well in good. I m doing Autowiring like this:

    @Autowired
        protected AerospikeClient aerospikeClient;

I have Autowired aerospike template like this:

  @Autowired
    public AerospikeTemplate aerospikeTemplate;

And it is giving me this Exceptions:

5372 ERROR [main] --- SpringApplication: Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'prePushAnalysisService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public org.springframework.data.aerospike.core.AerospikeTemplate com.matchinguu.analytics.core.service.PrePushAnalysisService.aerospikeTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aerospikeTemplate' defined in class path resource [com/matchinguu/analytics/ConfigurationHandler.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.aerospike.core.AerospikeTemplate]: Factory method 'aerospikeTemplate' threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)

Please guide me, what I am doing wrong. I use the same format for MongoDB and it is running fine.

specific exception is:

java.lang.NullPointerException
    at java.util.TreeMap.compare(TreeMap.java:1290)
    at java.util.TreeMap.put(TreeMap.java:538)
    at com.aerospike.helper.query.QueryEngine.refreshIndexes(QueryEngine.java:497)
    at com.aerospike.helper.query.QueryEngine.refreshCluster(QueryEngine.java:420)
    at com.aerospike.helper.query.QueryEngine.<init>(QueryEngine.java:108)
    at org.springframework.data.aerospike.core.AerospikeTemplate.<init>(AerospikeTemplate.java:135)

And I am following your repo example:

https://github.com/spring-projects/spring-data-aerospike/blob/master/src/main/java/org/springframework/data/aerospike/example/AerospikeApp.java

Hello Hafsa,

Have you resolved this problem with Autowired Annotation on Bean Objects? Because I have encountered the same problem!

I am also still facing this issue as Oct 24th 2016

I downloaded the spring-data-aerospike code and built it and using it.

added in gradle build file compile('org.springframework.data:spring-data-aerospike:1.0.1-SNAPSHOT')

along with

repositories {
    mavenLocal()
    mavenCentral()
}

But , Now i am getting an error

“required a bean named ‘aerospikeTemplate’ that could not be found” Action: Consider defining a bean named ‘aerospikeTemplate’ in your configuration.

I am having AeroSpikeConfiguration as below in package com.vkt.repository.configuration

@Configuration
@EnableAutoConfiguration
@EnableTransactionManagement

public class AerospikeConfiguration {
    public @Bean(destroyMethod = "close") AerospikeClient aerospikeClient() {
        ClientPolicy policy = new ClientPolicy();
        policy.failIfNotConnected = true;
        return new AerospikeClient(policy, "localhost", 3000);
    }

    public @Bean AerospikeTemplate aerospikeTemplate() {
        return new AerospikeTemplate(aerospikeClient(), "test");
    }
}

I have the below code in my Service Layer @EnableAerospikeRepositories(basePackages = "com.vkt.repository")

Any clue what could be wrong

Hello folks, I am facing the same issue also as on Dec 9, 2016. I downloaded the spring-data-aerospike code and built it and using it in pom.xml.

<dependency>
	<groupId>org.springframework.data</groupId>
	<artifactId>spring-data-aerospike</artifactId>
	<version>1.0.1-SNAPSHOT</version>
</dependency>

I have also tried all methods but could not resolve the issue

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aerospikeTemplate'

Hello!I encouter the same problem as you。have you solved the problem yet?