mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Ensure that spring.data.rest.* configuration takes effect
Previously, RepositoryRestMvcBootConfiguration was not annotated with @Configuration. This meant that it was processed in lite mode. Crucially, in lite mode, there’s no proxying so each call to the config() @Bean method from within other @Bean methods resulted in the creation of a new RepositoryRestConfiguration instance. Furthermore, as each of these instances wasn’t a Spring bean the configuration properties were not applied. This commit updates RepositoryRestMvcBootConfiguration to annotate it with @Configuration so that it’s no longer processed in lite mode. It also updates the unit tests and the Spring Data REST sample to verify that the baseUri can be configured using application.properties. Fixes gh-1675
This commit is contained in:
parent
6ec0b4ca81
commit
07cb8f2836
@ -46,6 +46,7 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguratio
|
||||
@ConditionalOnClass(RepositoryRestMvcConfiguration.class)
|
||||
public class RepositoryRestMvcAutoConfiguration {
|
||||
|
||||
@Configuration
|
||||
static class RepositoryRestMvcBootConfiguration extends
|
||||
RepositoryRestMvcConfiguration {
|
||||
|
||||
|
@ -30,6 +30,7 @@ import org.springframework.boot.test.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.data.rest.webmvc.BaseUri;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
@ -66,7 +67,11 @@ public class RepositoryRestMvcAutoConfigurationTests {
|
||||
assertNotNull(this.context.getBean(RepositoryRestMvcConfiguration.class));
|
||||
RepositoryRestConfiguration bean = this.context
|
||||
.getBean(RepositoryRestConfiguration.class);
|
||||
assertEquals("Custom baseURI not set", URI.create("foo"), bean.getBaseUri());
|
||||
URI expectedUri = URI.create("foo");
|
||||
assertEquals("Custom baseURI not set", expectedUri, bean.getBaseUri());
|
||||
BaseUri baseUri = this.context.getBean(BaseUri.class);
|
||||
assertEquals("Custom baseUri has not been applied to BaseUri bean", expectedUri,
|
||||
baseUri.getUri());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -0,0 +1 @@
|
||||
spring.data.rest.baseUri=/api
|
@ -69,7 +69,7 @@ public class SampleDataRestApplicationTests {
|
||||
public void findByNameAndCountry() throws Exception {
|
||||
|
||||
this.mvc.perform(
|
||||
get("/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia"))
|
||||
get("/api/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("_embedded.citys", hasSize(1)));
|
||||
}
|
||||
@ -78,7 +78,7 @@ public class SampleDataRestApplicationTests {
|
||||
public void findByContaining() throws Exception {
|
||||
|
||||
this.mvc.perform(
|
||||
get("/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK"))
|
||||
get("/api/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("_embedded.citys", hasSize(3)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user