Skip to content

Commit

Permalink
FMWK-278 Refactor configuration (#684)
Browse files Browse the repository at this point in the history
* refactor configuration, read from application.properties
---------
Co-authored-by: yrizhkov <[email protected]>
  • Loading branch information
agrgr authored Jan 8, 2024
1 parent 436b96e commit 8ef5cc0
Show file tree
Hide file tree
Showing 107 changed files with 730 additions and 636 deletions.
12 changes: 8 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ For non-blocking reactive API use `ReactiveAerospikeRepository`.
=== 3. Configuration

In order to configure Spring Data Aerospike you will need to create a configuration class that extends
`AbstractAerospikeDataConfiguration`, defines the relevant Spring Data Repositories via `@EnableAerospikeRepositories`
annotation and overrides `getHosts()` and `nameSpace()` methods with the required connection details.
`AbstractAerospikeDataConfiguration` and defines the relevant Spring Data Repositories via `@EnableAerospikeRepositories`
annotation.

NOTE: You can optionally override xref:#configure-data-settings[`configureDataSettings`] method of `AbstractAerospikeDataConfiguration` to further customize your configuration.
To set the connection details you can either override `getHosts()` and `nameSpace()` methods
of the `AbstractAerospikeDataConfiguration` class or define `spring-data-aerospike.connection.hosts` and
`spring-data-aerospike.connection.namespace` in `application.properties` file.

Here is a simple example of a configuration class that sets up a connection to a local Aerospike instance:
NOTE: You can further customize your configuration by changing other xref:#configuration[`settings`].

Here is a simple example of a configuration class that sets up a connection to a local Aerospike DB instance:

[source,java]
----
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springdata.commons>3.2.1</springdata.commons>
<springdata.keyvalue>3.2.1</springdata.keyvalue>
<springdata.spring-boot>3.2.1</springdata.spring-boot>
<spring-boot-starter-test>3.2.0</spring-boot-starter-test>
<spring-cloud-starter-bootstrap>4.1.0</spring-cloud-starter-bootstrap>
<maven.javadoc.plugin>3.3.0</maven.javadoc.plugin>
Expand Down Expand Up @@ -183,6 +184,12 @@
<artifactId>spring-data-keyvalue</artifactId>
<version>${springdata.keyvalue}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>${springdata.spring-boot}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ include::reference/template.adoc[]
include::reference/secondary-indexes.adoc[]
include::reference/indexed-annotation.adoc[]
include::reference/caching.adoc[]
include::reference/configure-data-settings.adoc[]
include::reference/configuration.adoc[]
include::spring-data-commons-docs/dependencies.adoc[]
include::spring-data-commons-docs/auditing.adoc[]

Expand Down
2 changes: 1 addition & 1 deletion src/main/asciidoc/reference/aerospike-object-mapping.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The following outlines what field will be mapped to the '_id' document field:

The following outlines what type of conversion, if any, will be done on the property mapped to the _id document field.

* By default, the type of the field annotated with `@id` is turned into a `String` to be stored in Aerospike database. If the original type cannot be persisted (see xref:#configure-data-settings.keep-original-key-types[keepOriginalKeyTypes] for details), it must be convertible to `String` and will be stored in the database as such, then converted back to the original type when the object is read. This is transparent to the application but needs to be considered if using external tools like `AQL` to view the data.
* By default, the type of the field annotated with `@id` is turned into a `String` to be stored in Aerospike database. If the original type cannot be persisted (see xref:#configuration.keep-original-key-types[keepOriginalKeyTypes] for details), it must be convertible to `String` and will be stored in the database as such, then converted back to the original type when the object is read. This is transparent to the application but needs to be considered if using external tools like `AQL` to view the data.
* If no field named "id" is present in the Java class then an implicit '_id' file will be generated by the driver but not mapped to a property or field of the Java class.

When querying and updating `AerospikeTemplate` will use the converter to handle conversions of the `Query` and `Update` objects that correspond to the above rules for saving documents so field names and types used in your queries will be able to match what is in your domain classes.
Expand Down
10 changes: 5 additions & 5 deletions src/main/asciidoc/reference/caching.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,17 @@ public class UserController {

=== Add @EnableCaching

==== SimpleSpringbootAerospikeCacheApplication
==== SimpleSpringBootAerospikeCacheApplication

Add `@EnableCaching` to the class that contains the main method.

[source,java]
----
@EnableCaching
@SpringBootApplication
public class SimpleSpringbootAerospikeCacheApplication {
public class SimpleSpringBootAerospikeCacheApplication {
public static void main(String[] args) {
SpringApplication.run(SimpleSpringbootAerospikeCacheApplication.class, args);
SpringApplication.run(SimpleSpringBootAerospikeCacheApplication.class, args);
}
}
----
Expand Down Expand Up @@ -252,7 +252,7 @@ aql> select * from test
+-----+-----------+----------+-------------+-------------------------------------+
| @user_key | name | @_class | email | age |
+-----+-----------+----------+-------------+-------------------------------------+
| "1" | "guthrie" | "com.aerospike.cache.simplespringbootaerospikecache.objects.User" | "[email protected]" | 35 |
| "1" | "guthrie" | "com.aerospike.cache.simpleSpringBootAerospikeCache.objects.User" | "[email protected]" | 35 |
+-----+-----------+----------+-------------+-------------------------------------+
----

Expand Down Expand Up @@ -315,6 +315,6 @@ aql> select * from test
+-----+-----------+----------+-------------+-------------------------------------+
| @user_key | name | @_class | email | age |
+-----+-----------+----------+-------------+-------------------------------------+
| "1" | "jimmy page" | "com.aerospike.cache.simplespringbootaerospikecache.objects.User" | "[email protected]" | 77 |
| "1" | "jimmy page" | "com.aerospike.cache.simpleSpringBootAerospikeCache.objects.User" | "[email protected]" | 77 |
+-----+-----------+----------+-------------+-------------------------------------+
----
Loading

0 comments on commit 8ef5cc0

Please sign in to comment.