Adopt RepositoryRestConfigurer and discourage subclassing
A RepositoryRestMvcConfiguration subclass provided by a user is problematic in a Spring Boot application as it causes RepositoryRestMvcConfiguration's bean declarations to be processed before any auto-configuration runs. One problem that this causes is that it switches off Boot's Jackson auto-configuration due to RepositoryRestMvcConfiguration having already declared multiple ObjectMapper beans. Unlike Boot's auto-configured ObjectMapper, none of these ObjectMappers are marked as @Primary. This then leads to wiring failures due to multiple candidates being available. To address this problem a new RepositoryRestConfigurer abstract has been introduced in Spring Data Gosling. Its use is now strongly preferred over subclassing RepositoryRestMvcConfiguration. Note that our own RepositoryRestMvcConfiguration subclass remains. It is imported as part of auto-configuration (avoiding the ordering problems described above), and provides configuration properties binding for RepositoryRestConfiguration. However, the Jackson ObjectMapper configuration has been moved out into a new RepositoryRestConfigurer implementation. While SpringBootRepositoryRestMvcConfiguration remains, this commit makes it package private to discourage users from subclassing it. While this may break existing applications, it, coupled with the documentation updates, will hopefully guide them toward using RepositoryRestConfigurer. Closes gh-3439
This commit is contained in:
@@ -1476,15 +1476,16 @@ respectively.
|
||||
|
||||
[[howto-use-exposing-spring-data-repositories-rest-endpoint]]
|
||||
=== Expose Spring Data repositories as REST endpoint
|
||||
|
||||
Spring Data REST can expose the `Repository` implementations as REST endpoints for you as
|
||||
long as Spring MVC has been enabled for the application.
|
||||
|
||||
Spring Boot exposes as set of useful properties from the `spring.data.rest` namespace that
|
||||
customize the {spring-data-rest-javadoc}/core/config/RepositoryRestConfiguration.{dc-ext}[`RepositoryRestConfiguration`].
|
||||
If you need to provide additional customization, you can create a `@Configuration` class
|
||||
that extends `SpringBootRepositoryRestMvcConfiguration`. This class supports the same
|
||||
functionality as `RepositoryRestMvcConfiguration`, but allows you to continue using
|
||||
`spring.data.rest.*` properties.
|
||||
customize the
|
||||
{spring-data-rest-javadoc}/core/config/RepositoryRestConfiguration.{dc-ext}[`RepositoryRestConfiguration`].
|
||||
If you need to provide additional customization, you should use a
|
||||
{spring-data-rest-javadoc}/core/config/RepositoryRestConfigurer.{dc-ext}[`RepositoryRestConfigurer`]
|
||||
bean.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user