mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Order internal RepositoryRestConfigurer
This commit provides an order of zero for the RepositoryRestConfigurer that is used internally to configure the `RepositoryRestConfiguration`. In practice, an unordered `RepositoryRestConfigurer` will run after ours. Closes gh-7981
This commit is contained in:
parent
ddf1408679
commit
3e05329fd7
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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,6 +19,7 @@ package org.springframework.boot.autoconfigure.data.rest;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
@ -32,6 +33,7 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Order(0)
|
||||
class SpringBootRepositoryRestConfigurer extends RepositoryRestConfigurerAdapter {
|
||||
|
||||
@Autowired(required = false)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@ -40,6 +40,7 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy.RepositoryDetectionStrategies;
|
||||
import org.springframework.data.rest.webmvc.BaseUri;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
@ -54,6 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class RepositoryRestMvcAutoConfigurationTests {
|
||||
|
||||
@ -118,6 +120,22 @@ public class RepositoryRestMvcAutoConfigurationTests {
|
||||
assertThat(bean.isEnableEnumTranslation()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithCustomConfigurer() {
|
||||
load(TestConfigurationWithConfigurer.class,
|
||||
"spring.data.rest.detection-strategy=visibility",
|
||||
"spring.data.rest.default-media-type:application/my-json");
|
||||
assertThat(this.context.getBean(RepositoryRestMvcConfiguration.class))
|
||||
.isNotNull();
|
||||
RepositoryRestConfiguration bean = this.context
|
||||
.getBean(RepositoryRestConfiguration.class);
|
||||
assertThat(bean.getRepositoryDetectionStrategy())
|
||||
.isEqualTo(RepositoryDetectionStrategies.ALL);
|
||||
assertThat(bean.getDefaultMediaType())
|
||||
.isEqualTo(MediaType.parseMediaType("application/my-custom-json"));
|
||||
assertThat(bean.getMaxPageSize()).isEqualTo(78);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void backOffWithCustomConfiguration() {
|
||||
load(TestConfigurationWithRestMvcConfig.class, "spring.data.rest.base-path:foo");
|
||||
@ -179,6 +197,11 @@ public class RepositoryRestMvcAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Import({ TestConfiguration.class, TestRepositoryRestConfigurer.class })
|
||||
protected static class TestConfigurationWithConfigurer {
|
||||
|
||||
}
|
||||
|
||||
@Import({ TestConfiguration.class, RepositoryRestMvcConfiguration.class })
|
||||
protected static class TestConfigurationWithRestMvcConfig {
|
||||
|
||||
@ -198,4 +221,14 @@ public class RepositoryRestMvcAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
static class TestRepositoryRestConfigurer extends RepositoryRestConfigurerAdapter {
|
||||
@Override
|
||||
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
|
||||
config.setRepositoryDetectionStrategy(RepositoryDetectionStrategies.ALL);
|
||||
config.setDefaultMediaType(MediaType.parseMediaType(
|
||||
"application/my-custom-json"));
|
||||
config.setMaxPageSize(78);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1952,6 +1952,10 @@ If you need to provide additional customization, you should use a
|
||||
{spring-data-rest-javadoc}/webmvc/config/RepositoryRestConfigurer.{dc-ext}[`RepositoryRestConfigurer`]
|
||||
bean.
|
||||
|
||||
NOTE: If you don't specify any order on your custom `RepositoryRestConfigurer` it will run
|
||||
after the one Spring Boot uses internally. If you need to specify an order, make sure it
|
||||
is higher than 0.
|
||||
|
||||
|
||||
|
||||
[[howto-configure-a-component-that-is-used-by-JPA]]
|
||||
|
Loading…
Reference in New Issue
Block a user