Change AnnotatedHandlerRepositoryEventListener into a BeanPostProcessor which works better all around and processes every bean, looking for event handlers.
This commit is contained in:
@@ -7,6 +7,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.data.rest.repository.UriToDomainObjectUriResolver;
|
||||
import org.springframework.data.rest.repository.context.AnnotatedHandlerBeanPostProcessor;
|
||||
import org.springframework.data.rest.repository.context.ValidatingRepositoryEventListener;
|
||||
import org.springframework.data.rest.repository.jpa.JpaRepositoryExporter;
|
||||
import org.springframework.data.rest.webmvc.json.JsonSchemaController;
|
||||
@@ -57,6 +58,16 @@ public class RepositoryRestMvcConfiguration {
|
||||
return new PersistenceAnnotationBeanPostProcessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link org.springframework.beans.factory.config.BeanPostProcessor} to turn beans annotated as {@link
|
||||
* org.springframework.data.rest.repository.annotation.RepositoryEventHandler}s.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean public AnnotatedHandlerBeanPostProcessor annotatedHandlerBeanPostProcessor() {
|
||||
return new AnnotatedHandlerBeanPostProcessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the pre-defined {@link JpaRepositoryExporter} defined by the user or create a default one.
|
||||
*
|
||||
|
||||
@@ -94,7 +94,7 @@ public class ApplicationRestConfig {
|
||||
|
||||
@Bean public Module customModule() {
|
||||
return new Module() {
|
||||
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
|
||||
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
|
||||
@Override public String getModuleName() {
|
||||
return "custom";
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.springframework.data.rest.test.webmvc;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.rest.repository.annotation.HandleAfterSave;
|
||||
import org.springframework.data.rest.repository.annotation.RepositoryEventHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
@Component
|
||||
@RepositoryEventHandler(Person.class)
|
||||
public class AfterSavePersonHandler {
|
||||
|
||||
private final static Logger LOG = LoggerFactory.getLogger(AfterSavePersonHandler.class);
|
||||
|
||||
@HandleAfterSave
|
||||
public void handleAfterSave(Person person) {
|
||||
LOG.info("saved person: " + person);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import org.springframework.data.rest.repository.annotation.RestResource;
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
@RestResource(path = "people", rel = "peeps")
|
||||
@RestResource(path = "people", rel = "people")
|
||||
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="baseUri" class="java.net.URI">
|
||||
<constructor-arg value="http://localhost:3000/api"/>
|
||||
<constructor-arg value="http://localhost:8080/data"/>
|
||||
</bean>
|
||||
|
||||
<bean id="config" class="org.springframework.data.rest.webmvc.RepositoryRestConfiguration"
|
||||
|
||||
Reference in New Issue
Block a user