From 8618b7df8e0b336cefe1c01c99b2701256e5461f Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 24 Jun 2014 23:38:16 +0200 Subject: [PATCH] DATAREST-182 - Removed obsolete wirings from AbstractRepositoryRestController. Removed the wirings for PlatformTransactionManager and ValidationExceptionHandler from AbstractRepositoryRestController. Removed the latter entirely as it doesn't seem to be used anywhere anyway. --- .../AbstractRepositoryRestController.java | 6 ----- .../RepositoryRestMvcConfiguration.java | 14 ----------- .../support/ValidationExceptionHandler.java | 24 ------------------- 3 files changed, 44 deletions(-) delete mode 100644 spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/ValidationExceptionHandler.java diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java index 8d3047a58..e2123235d 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java @@ -25,7 +25,6 @@ import java.util.Locale; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.MessageSourceAware; import org.springframework.context.support.MessageSourceAccessor; @@ -37,7 +36,6 @@ import org.springframework.data.rest.core.RepositoryConstraintViolationException import org.springframework.data.rest.core.mapping.ResourceMetadata; import org.springframework.data.rest.webmvc.support.ExceptionMessage; import org.springframework.data.rest.webmvc.support.RepositoryConstraintViolationExceptionMessage; -import org.springframework.data.rest.webmvc.support.ValidationExceptionHandler; import org.springframework.data.web.PagedResourcesAssembler; import org.springframework.hateoas.Link; import org.springframework.hateoas.Resource; @@ -47,7 +45,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; -import org.springframework.transaction.PlatformTransactionManager; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; @@ -61,9 +58,6 @@ class AbstractRepositoryRestController implements MessageSourceAware { private static final Logger LOG = LoggerFactory.getLogger(AbstractRepositoryRestController.class); - @Autowired(required = false) private ValidationExceptionHandler handler; - @Autowired(required = false) private PlatformTransactionManager txMgr; - private final PagedResourcesAssembler pagedResourcesAssembler; private MessageSourceAccessor messageSourceAccessor; diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java index f125b4c09..fc39b7993 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java @@ -35,7 +35,6 @@ import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.ImportResource; -import org.springframework.context.annotation.Lazy; import org.springframework.context.support.MessageSourceAccessor; import org.springframework.context.support.ReloadableResourceBundleMessageSource; import org.springframework.core.annotation.AnnotationAwareOrderComparator; @@ -81,7 +80,6 @@ import org.springframework.data.rest.webmvc.support.DefaultedPageableHandlerMeth import org.springframework.data.rest.webmvc.support.HttpMethodHandlerMethodArgumentResolver; import org.springframework.data.rest.webmvc.support.JpaHelper; import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks; -import org.springframework.data.rest.webmvc.support.ValidationExceptionHandler; import org.springframework.data.util.AnnotatedTypeScanner; import org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver; import org.springframework.data.web.HateoasSortHandlerMethodArgumentResolver; @@ -131,8 +129,6 @@ import com.fasterxml.jackson.databind.SerializationFeature; @Import(SpringDataJacksonConfiguration.class) public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebConfiguration { - private static final boolean IS_JAVAX_VALIDATION_AVAILABLE = ClassUtils.isPresent( - "javax.validation.ConstraintViolationException", RepositoryRestMvcConfiguration.class.getClassLoader()); private static final boolean IS_JPA_AVAILABLE = ClassUtils.isPresent("javax.persistence.EntityManager", RepositoryRestMvcConfiguration.class.getClassLoader()); @@ -206,16 +202,6 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon return listener; } - @Bean - @Lazy - public ValidationExceptionHandler validationExceptionHandler() { - if (IS_JAVAX_VALIDATION_AVAILABLE) { - return new ValidationExceptionHandler(); - } else { - return null; - } - } - @Bean public JpaHelper jpaHelper() { if (IS_JPA_AVAILABLE) { diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/ValidationExceptionHandler.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/ValidationExceptionHandler.java deleted file mode 100644 index 290fc1295..000000000 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/ValidationExceptionHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.springframework.data.rest.webmvc.support; - -import java.util.Locale; -import javax.validation.ConstraintViolationException; - -import org.springframework.context.MessageSource; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.util.Assert; - -/** - * @author Jon Brisbin - */ -public class ValidationExceptionHandler { - - public ResponseEntity handleValidationException(RuntimeException ex, MessageSource msgsrc, Locale locale) { - Assert.isAssignable(ConstraintViolationException.class, ex.getClass()); - return new ResponseEntity(new ConstraintViolationExceptionMessage( - (ConstraintViolationException) ex, msgsrc, locale), HttpStatus.BAD_REQUEST - - ); - } - -}