From 8d0fc660ce467601d85b0840ae473ec7c4b421c6 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 5 Jun 2013 20:49:54 +0200 Subject: [PATCH] DATAREST-83 - Removed type level @RequestMapping annotations. Removed type level @RequestMapping annotations to prevent Spring MVC from picking up the controllers in its default configuration. --- .../rest/webmvc/RepositoryController.java | 2 +- .../webmvc/RepositoryEntityController.java | 14 +++++--- ...RepositoryPropertyReferenceController.java | 32 +++++++------------ .../webmvc/RepositorySearchController.java | 8 +++-- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryController.java index f53997ce1..1dea9cabd 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryController.java @@ -16,7 +16,6 @@ import static org.springframework.data.rest.repository.support.ResourceMappingUt /** * @author Jon Brisbin */ -@RequestMapping("/") public class RepositoryController extends AbstractRepositoryRestController { @Autowired @@ -33,6 +32,7 @@ public class RepositoryController extends AbstractRepositoryRestController { } @RequestMapping( + value = "/", method = RequestMethod.GET, produces = { "application/json", diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java index 3f04873dc..529bbae44 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java @@ -39,10 +39,11 @@ import java.util.List; /** * @author Jon Brisbin */ -@RequestMapping("/{repository}") @SuppressWarnings({"rawtypes"}) public class RepositoryEntityController extends AbstractRepositoryRestController { + private static final String BASE_MAPPING = "/{repository}"; + @Autowired private DomainObjectMerger domainObjectMerger; @Autowired @@ -61,7 +62,7 @@ public class RepositoryEntityController extends AbstractRepositoryRestController } @RequestMapping( - value = "/schema", + value = BASE_MAPPING + "/schema", method = RequestMethod.GET, produces = { "application/schema+json" @@ -73,6 +74,7 @@ public class RepositoryEntityController extends AbstractRepositoryRestController } @RequestMapping( + value = BASE_MAPPING, method = RequestMethod.GET, produces = { "application/json", @@ -126,6 +128,7 @@ public class RepositoryEntityController extends AbstractRepositoryRestController @SuppressWarnings({"unchecked"}) @RequestMapping( + value = BASE_MAPPING, method = RequestMethod.GET, produces = { "application/x-spring-data-compact+json", @@ -151,6 +154,7 @@ public class RepositoryEntityController extends AbstractRepositoryRestController @SuppressWarnings({"unchecked"}) @RequestMapping( + value = BASE_MAPPING, method = RequestMethod.POST, consumes = { "application/json" @@ -197,7 +201,7 @@ public class RepositoryEntityController extends AbstractRepositoryRestController @SuppressWarnings({"unchecked"}) @RequestMapping( - value = "/{id}", + value = BASE_MAPPING + "/{id}", method = RequestMethod.GET, produces = { "application/json", @@ -236,7 +240,7 @@ public class RepositoryEntityController extends AbstractRepositoryRestController @SuppressWarnings({"unchecked"}) @RequestMapping( - value = "/{id}", + value = BASE_MAPPING + "/{id}", method = RequestMethod.PUT, consumes = { "application/json" @@ -295,7 +299,7 @@ public class RepositoryEntityController extends AbstractRepositoryRestController @SuppressWarnings({"unchecked"}) @RequestMapping( - value = "/{id}", + value = BASE_MAPPING + "/{id}", method = RequestMethod.DELETE ) @ResponseBody diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.java index 75c2b5938..cce8d03ab 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.java @@ -16,7 +16,6 @@ import org.springframework.core.convert.TypeDescriptor; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.model.BeanWrapper; -import org.springframework.data.repository.core.RepositoryInformation; import org.springframework.data.repository.support.DomainClassConverter; import org.springframework.data.repository.support.Repositories; import org.springframework.data.rest.config.RepositoryRestConfiguration; @@ -33,7 +32,6 @@ import org.springframework.hateoas.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -43,14 +41,16 @@ import org.springframework.web.bind.annotation.ResponseBody; /** * @author Jon Brisbin + * @author Oliver Gierke */ -@Controller -@RequestMapping("/{repository}/{id}/{property}") +@SuppressWarnings({"unchecked", "rawtypes"}) public class RepositoryPropertyReferenceController extends AbstractRepositoryRestController { + + private static final String BASE_MAPPING = "/{repository}/{id}/{property}"; public RepositoryPropertyReferenceController(Repositories repositories, RepositoryRestConfiguration config, - DomainClassConverter domainClassConverter, + DomainClassConverter domainClassConverter, ConversionService conversionService, EntityLinks entityLinks) { super(repositories, @@ -60,8 +60,8 @@ public class RepositoryPropertyReferenceController extends AbstractRepositoryRes entityLinks); } - @SuppressWarnings({"unchecked"}) @RequestMapping( + value = BASE_MAPPING, method = RequestMethod.GET, produces = { "application/json", @@ -131,8 +131,8 @@ public class RepositoryPropertyReferenceController extends AbstractRepositoryRes return resourceResponse(headers, responseResource, HttpStatus.OK); } - @SuppressWarnings({"unchecked"}) @RequestMapping( + value = BASE_MAPPING, method = RequestMethod.DELETE ) @ResponseBody @@ -178,9 +178,8 @@ public class RepositoryPropertyReferenceController extends AbstractRepositoryRes return resourceResponse(null, EMPTY_RESOURCE, HttpStatus.NO_CONTENT); } - @SuppressWarnings({"unchecked"}) @RequestMapping( - value = "/{propertyId}", + value = BASE_MAPPING + "/{propertyId}", method = RequestMethod.GET, produces = { "application/json", @@ -242,8 +241,8 @@ public class RepositoryPropertyReferenceController extends AbstractRepositoryRes return resourceResponse(headers, responseResource, HttpStatus.OK); } - @SuppressWarnings({"unchecked"}) @RequestMapping( + value = BASE_MAPPING, method = RequestMethod.GET, produces = { "application/x-spring-data-compact+json", @@ -302,8 +301,8 @@ public class RepositoryPropertyReferenceController extends AbstractRepositoryRes return resourceResponse(null, new Resource(EMPTY_RESOURCE_LIST, links), HttpStatus.OK); } - @SuppressWarnings({"unchecked"}) @RequestMapping( + value = BASE_MAPPING, method = { RequestMethod.POST, RequestMethod.PUT @@ -372,9 +371,8 @@ public class RepositoryPropertyReferenceController extends AbstractRepositoryRes return resourceResponse(null, EMPTY_RESOURCE, HttpStatus.CREATED); } - @SuppressWarnings({"unchecked"}) @RequestMapping( - value = "/{propertyId}", + value = BASE_MAPPING + "/{propertyId}", method = RequestMethod.DELETE ) @ResponseBody @@ -446,7 +444,6 @@ public class RepositoryPropertyReferenceController extends AbstractRepositoryRes TypeDescriptor.valueOf(type)); } - @SuppressWarnings({"unchecked"}) private Resource doWithReferencedProperty(RepositoryRestRequest repoRequest, String id, String propertyPath, @@ -485,9 +482,6 @@ public class RepositoryPropertyReferenceController extends AbstractRepositoryRes final Class propertyType; final Object propertyValue; final BeanWrapper wrapper; - final RepositoryInformation propertyRepoInfo; - final Object propertyRepo; - final RepositoryMethodInvoker repoMethodInvoker; private ReferencedProperty(PersistentProperty property, Object propertyValue, @@ -502,11 +496,7 @@ public class RepositoryPropertyReferenceController extends AbstractRepositoryRes } else { this.propertyType = property.getType(); } - this.propertyRepoInfo = repositories.getRepositoryInformationFor(propertyType); this.entity = repositories.getPersistentEntity(propertyType); - this.propertyRepo = repositories.getRepositoryFor(entity.getType()); - this.repoMethodInvoker = new RepositoryMethodInvoker(propertyRepo, propertyRepoInfo); } } - } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java index 6e5c14e77..730672f54 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java @@ -32,9 +32,10 @@ import org.springframework.web.bind.annotation.ResponseBody; /** * @author Jon Brisbin */ -@RequestMapping("/{repository}/search") public class RepositorySearchController extends AbstractRepositoryRestController { + private static final String BASE_MAPPING = "/{repository}/search"; + public RepositorySearchController(Repositories repositories, RepositoryRestConfiguration config, DomainClassConverter domainClassConverter, @@ -48,6 +49,7 @@ public class RepositorySearchController extends AbstractRepositoryRestController } @RequestMapping( + value = BASE_MAPPING, method = RequestMethod.GET, produces = { "application/json", @@ -66,7 +68,7 @@ public class RepositorySearchController extends AbstractRepositoryRestController } @RequestMapping( - value = "/{method}", + value = BASE_MAPPING + "/{method}", method = RequestMethod.GET, produces = { "application/json", @@ -145,7 +147,7 @@ public class RepositorySearchController extends AbstractRepositoryRestController } @RequestMapping( - value = "/{method}", + value = BASE_MAPPING +"/{method}", method = RequestMethod.GET, produces = { "application/x-spring-data-compact+json"