Avoid extending from RepositoryRestMvcConfiguration

This commit moves Spring Boot's customizations for Spring Data Rest to
the existing SpringBootRepositoryRestConfigurer.

Closes gh-6581
pull/6666/head
Stephane Nicoll 8 years ago
parent 6c0d32550e
commit 919d6b4b2e

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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, @AutoConfigureAfter({ HttpMessageConvertersAutoConfiguration.class,
JacksonAutoConfiguration.class }) JacksonAutoConfiguration.class })
@EnableConfigurationProperties(RepositoryRestProperties.class) @EnableConfigurationProperties(RepositoryRestProperties.class)
@Import(SpringBootRepositoryRestMvcConfiguration.class) @Import(RepositoryRestMvcConfiguration.class)
public class RepositoryRestMvcAutoConfiguration { public class RepositoryRestMvcAutoConfiguration {
@Bean @Bean

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired; 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.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
/** /**
* A {@code RepositoryRestConfigurer} that applies our configuration to Spring Data REST. * A {@code RepositoryRestConfigurer} that applies that applies configuration items
* Specifically, if a {@link Jackson2ObjectMapperBuilder} is available, it is used to * from the {@code spring.data.rest} namespace to Spring Data REST. Also, if a
* configure Spring Data REST's {@link ObjectMapper ObjectMappers}. * {@link Jackson2ObjectMapperBuilder} is available, it is used to configure Spring
* Data REST's {@link ObjectMapper ObjectMappers}.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Stephane Nicoll
*/ */
class SpringBootRepositoryRestConfigurer extends RepositoryRestConfigurerAdapter { class SpringBootRepositoryRestConfigurer extends RepositoryRestConfigurerAdapter {
@Autowired(required = false) @Autowired(required = false)
private Jackson2ObjectMapperBuilder objectMapperBuilder; private Jackson2ObjectMapperBuilder objectMapperBuilder;
@Autowired
private RepositoryRestProperties properties;
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
this.properties.applyTo(config);
}
@Override @Override
public void configureJacksonObjectMapper(ObjectMapper objectMapper) { public void configureJacksonObjectMapper(ObjectMapper objectMapper) {
if (this.objectMapperBuilder != null) { if (this.objectMapperBuilder != 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.
* <p>
*
* @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;
}
}
Loading…
Cancel
Save