diff --git a/src/reference/docbook/events.xml b/src/reference/docbook/events.xml
new file mode 100644
index 000000000..6478a7afd
--- /dev/null
+++ b/src/reference/docbook/events.xml
@@ -0,0 +1,137 @@
+
+
+
+ Events
+
+ There are six different events that the REST exporter emits throughout the process of working with an entity.
+ Those are:
+
+
+
+ BeforeCreateEvent
+
+
+ AfterCreateEvent
+
+
+ BeforeSaveEvent
+
+
+ AfterSaveEvent
+
+
+ BeforeLinkSaveEvent
+
+
+ AfterLinkSaveEvent
+
+
+ BeforeDeleteEvent
+
+
+ AfterDeleteEvent
+
+
+
+
+
+ Writing an
+ ApplicationListener
+
+
+ There is an abstract class you can subclass which listens for these kinds of events and calls
+ the appropriate method based on the event type. You just override the methods for
+ the events you're interested in.
+
+
+
+
+ One thing to note with this approach, however, is that it makes no distinction based on
+ the type of the entity. You'll have to inspect that yourself.
+
+
+
+
+
+ Writing an annotated handler
+
+ Another approach is to use an annotated handler, which does filter events based on domain type.
+
+ To declare a handler, create a POJO and put the
+ @RepositoryEventHandler
+ annotation on it. This tells the
+ BeanPostProcessor
+ that this class needs to be inspected for handler methods.
+
+
+ Once it finds a bean with this annotation, it iterates over the exposed methods and looks for
+ annotations that correspond to the event you're interested in. For example, to handle BeforeSaveEvents
+ in an annotated POJO for different kinds of domain types, you'd define your class like this:
+
+
+
+
+ You can also declare the domain type at the class level:
+
+
+
+
+ Just declare an instance of your annotated bean in your
+ ApplicationContext
+ and the
+ BeanPostProcessor
+ that is by default created in
+ RepositoryRestMvcConfiguration
+ will inspect the bean for handlers and wire them to the correct events.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/reference/docbook/index.xml b/src/reference/docbook/index.xml
index 189e86074..b0522efce 100644
--- a/src/reference/docbook/index.xml
+++ b/src/reference/docbook/index.xml
@@ -47,6 +47,7 @@
+
\ No newline at end of file
diff --git a/src/reference/docbook/validation.xml b/src/reference/docbook/validation.xml
index d7fdf9f01..3d1f9490b 100644
--- a/src/reference/docbook/validation.xml
+++ b/src/reference/docbook/validation.xml
@@ -6,23 +6,44 @@
Validation
- Integrating validation into Spring Data REST is as easy as registering your
+ There are two ways to register a
Validator
- implementation with the
- ValidatingRepositoryEventListener, whose job it is to trigger
- validators whenever certain events happen inside Spring Data REST.
+ instance in Spring Data REST: wire it by bean name or register the validator manually. For the majority of cases,
+ the simple bean name prefix style will be sufficient.
- To add your validators, override the
- configureValidatingRepositoryEventListener
- method and call the
- addValidator
- method:
+ In order to tell Spring Data REST you want a particular
+ Validator
+ assigned to a particular event, you simply prefix the bean name with the event you're interested in. For example, to
+ validate instances of the
+ Person
+ class before new ones are saved into the repository, you would declare an instance of a
+ Validator<Person>
+ in your
+ ApplicationContext
+ with the bean name "beforeCreatePersonValidator". Since the prefix "beforeCreate" matches a known Spring Data REST
+ event, that validator will be wired to the correct event.
+
-
+ Assigning Validators manually
+
+ If you would rather not use the bean name prefix approach, then you simply need to register an instance of
+ your validator with the bean who's job it is to invoke validators after the correct event. In your configuration
+ that subclasses Spring Data REST's
+ RepositoryRestMvcConfiguration, override the
+ configureValidatingRepositoryEventListener
+ method and call the
+ addValidator
+ method on the
+ ValidatingRepositoryEventListener, passing the event you want this validator
+ to be triggered on, and an instance of the validator.
+
+
-
+
+
\ No newline at end of file