Search code examples
spring-bootaerospike

How to make Set using spring-data-aerospike


Environment:

  • spring-boot v2.0.4 RELEASE
  • spring-data-aerospike v2.0.1.RELEASE
  • java - 8

Here are my application code and properties.

// application.properties
aerospike.hosts=xxx:3000
aerospike.namespace=test

// aerospike configuration class
@Configuration
@RequiredArgsConstructor
@EnableConfigurationProperties(AerospikeConfiguration.AerospikeConfigurationProperties.class)
@EnableAerospikeRepositories(basePackageClassses = TestAeroRepository.class)
public class AerospikeConfiguration extends AbstractAerospikeDataConfiguration {
  private final AerospikeConfigurationProperties aerospikeConfigurationProperties;

  @Override
  protected Collection<Host> getHosts() {
      return Host.parseServiceHosts(aerospikeConfigurationProperties.getHosts());
  }

  @Override
  protected String nameSpace() {
    return aerospikeConfigurationProperties.getNamespace();
  }

  @Data
  @Validate
  @ConfigurationProperties("aerospike")
  public static class AerospikeConfigurationProperties {
     @NotEmpty
     String hsots;

     @NotEmpty
     String namespace;
  }
}

# Entity class
@Value
@Document
@Builder(toBuilder = true)
@AllArgsConstructor
public class testEntity() {
   @Id
   int id;

   @Field
   String name;

   @Field
   String timestamp;
}

@Repository
public interface TestAeroRepository extends AerospikeRepository<TestEntity, Integer> {
}

public interface TestAeroService {
  void save();
}

@Service
@RequiredArgsConstructor
public class TestAeroServiceImpl implements TestAeroService {
  private final TestAeroRepository testAeroRepository;

  @Override
  public void save(TestEntity entity) {
    testAeroRepository.save(entity);
  }
}

I checked Aerospike client connection has no problem. But error is occurred when save() method is executed.

org.springframework.cglib.core.ReflectUtils.defineClass(Ljava/lang/String;[BLjava/lang/ClassLoader;Ljava/security/ProtectionDomain;Ljava/lang/Class;)Ljava/lang/Class;

Have to make sets before execute the application?
I didn't make sets. Any problem with my code?


Solution

  • You’re using an old version of spring-data-aerospike (2.0.1.RELEASE was released on April 2019) is there any chance you can upgrade to the latest version? 2.4.2.RELEASE

    You can see how to setup a simple spring data aerospike application here: https://medium.com/aerospike-developer-blog/simple-web-application-using-java-spring-boot-aerospike-database-and-docker-ad13795e0089

    Please share the entire project’s code and the entire exception.

    I would look into:

    1. The configuration class (The Aerospike Beans creation).
    2. The content of the testEntity class - are you using @Id annotation on the primary key field?
    3. Extending the repository class with specifying the testEntity object (… extends AerospikeRepository<testEntity, Object> {) you can see an example in the link I added.