From 919d6b4b2e0d281ab8d509655c2b0255a27e0659 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 16 Aug 2016 17:54:51 +0200 Subject: [PATCH] Avoid extending from RepositoryRestMvcConfiguration This commit moves Spring Boot's customizations for Spring Data Rest to the existing SpringBootRepositoryRestConfigurer. Closes gh-6581 --- .../RepositoryRestMvcAutoConfiguration.java | 4 +- .../SpringBootRepositoryRestConfigurer.java | 19 +++++-- ...ingBootRepositoryRestMvcConfiguration.java | 49 ------------------- 3 files changed, 17 insertions(+), 55 deletions(-) delete mode 100644 spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.java diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfiguration.java index ab3b46b225..d68c290827 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguratio @AutoConfigureAfter({ HttpMessageConvertersAutoConfiguration.class, JacksonAutoConfiguration.class }) @EnableConfigurationProperties(RepositoryRestProperties.class) -@Import(SpringBootRepositoryRestMvcConfiguration.class) +@Import(RepositoryRestMvcConfiguration.class) public class RepositoryRestMvcAutoConfiguration { @Bean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java index 01db7671dd..8570000390 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,21 +19,32 @@ package org.springframework.boot.autoconfigure.data.rest; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.rest.core.config.RepositoryRestConfiguration; import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; /** - * A {@code RepositoryRestConfigurer} that applies our configuration to Spring Data REST. - * Specifically, if a {@link Jackson2ObjectMapperBuilder} is available, it is used to - * configure Spring Data REST's {@link ObjectMapper ObjectMappers}. + * A {@code RepositoryRestConfigurer} that applies that applies configuration items + * from the {@code spring.data.rest} namespace to Spring Data REST. Also, if a + * {@link Jackson2ObjectMapperBuilder} is available, it is used to configure Spring + * Data REST's {@link ObjectMapper ObjectMappers}. * * @author Andy Wilkinson + * @author Stephane Nicoll */ class SpringBootRepositoryRestConfigurer extends RepositoryRestConfigurerAdapter { @Autowired(required = false) private Jackson2ObjectMapperBuilder objectMapperBuilder; + @Autowired + private RepositoryRestProperties properties; + + @Override + public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { + this.properties.applyTo(config); + } + @Override public void configureJacksonObjectMapper(ObjectMapper objectMapper) { if (this.objectMapperBuilder != null) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.java deleted file mode 100644 index a14fe2a5f1..0000000000 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.autoconfigure.data.rest; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.rest.core.config.RepositoryRestConfiguration; -import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; - -/** - * A specialized {@link RepositoryRestMvcConfiguration} that applies configuration items - * from the {@code spring.data.rest} namespace. - *

- * - * @author Stephane Nicoll - * @since 1.2.2 - */ -@Configuration -class SpringBootRepositoryRestMvcConfiguration extends RepositoryRestMvcConfiguration { - - private final RepositoryRestProperties properties; - - SpringBootRepositoryRestMvcConfiguration(RepositoryRestProperties properties) { - this.properties = properties; - } - - @Bean - @Override - public RepositoryRestConfiguration config() { - RepositoryRestConfiguration config = super.config(); - this.properties.applyTo(config); - return config; - } - -}