[[SpringDatastoreConfiguration]]
=== Datastore configuration

The Spring integration module provides a number of methods to extend and configure a <<Datastore>> when a  `Datastore` instance is registered as a _bean_ in the Spring context.

TIP: See the <<Datastore>> section for information about the `Datastore` API.

[[DatastoreResolver]]
==== DatastoreResolver

The link:{apidir}/com/holonplatform/spring/DatastoreResolver.html[DatastoreResolver^] annotation can be used to annotate link:{apidir}/com/holonplatform/core/ExpressionResolver.html[ExpressionResolver^] type beans to automatically register them into a `Datastore` implementation.

The `datastoreBeanName()` annotation attribute can be used to uniquely identify the `Datastore` bean into which register the
resolver, if more than one `Datastore` type bean is present in the Spring application context.

[[DatastoreCommodityFactory]]
==== DatastoreCommodityFactory

The link:{apidir}/com/holonplatform/spring/DatastoreCommodityFactory.html[DatastoreCommodityFactory^] annotation can be used to annotate link:{apidir}/com/holonplatform/core/datastore/DatastoreCommodityFactory.html[DatastoreCommodityFactory^] type beans to automatically register them into a `Datastore` implementation.

The `datastoreBeanName()` annotation attribute can be used to uniquely identify the `Datastore` bean into which register the
factory, if more than one `Datastore` type bean is present in the Spring application context.

IMPORTANT: Each concrete `Datastore` implementation could provide a specific `DatastoreCommodityFactory` base type to be used to register commodity factories. See specific `Datastore` implementations documentation for further information.

[[DatastorePostProcessor]]
==== DatastorePostProcessor

The link:{apidir}/com/holonplatform/spring/DatastorePostProcessor.html[DatastorePostProcessor^] interface can be used to configure a `Datastore` bean, right after it is initialized in the Spring application context.

A Spring bean class implementing this interface is automatically detected and the method
`postProcessDatastore(Datastore, String)` is called at `Datastore` bean initialization time. 

The `Datastore` bean *instance* and the `Datastore` bean *name* are provided as method parameters. When more than one `Datastore` type bean is present in the Spring application context, the `postProcessDatastore` will be called one time for each available `Datastore` bean.

For example, the post processor can be used to register additional `ExpressionResolver` or `DatastoreCommodityFactory`.

NOTE: The `DatastorePostProcessor` type beans must be registered using the `singleton` scope.

[[EnableDatastoreConfiguration]]
==== Automatic `Datastore` beans configuration using `@EnableDatastoreConfiguration`

The link:{apidir}/com/holonplatform/spring/EnableDatastoreConfiguration.html[EnableDatastoreConfiguration^] annotation can be used on Spring configuration classes to *automatically detect and configure* the `Datastore` configuration beans listed above.

When the `@EnableDatastoreConfiguration` is present, the following beans will be auto-detected in Spring context and automatically registered/applied to any `Datastore` type Spring bean:

* <<DatastoreResolver>> annotated beans to automatically register _expression resolvers_.
* <<DatastoreCommodityFactory>> annotated beans to automatically register _commodity factories_.
* <<DatastorePostProcessor>> type beans to configure a `Datastore` bean right after it is initialized in the Spring application context.

[source, java]
----
include::{examplesdir}/com/holonplatform/core/examples/ExampleSpring.java[tag=datastoreconfig1,indent=0]
----
<1> Use the `@EnableDatastoreConfiguration` to automatically register suitable `Datastore` configuration beans into the `Datastore` bean definition
