Extending RepositoryRestMvcConfiguration prevents spring.data.rest properties from taking effect
See original GitHub issueI have found a problem caused by extended RepositoryRestMvcConfiguration
to add custom functionality, like custom validators. I’m using Spring-Boot 1.2.1.
When you extend RepositoryRestMvcConfiguration
properties like spring.data.rest.baseUri
do not work because the @ConfigurationProperties(prefix = "spring.data.rest")
is defined in RepositoryRestMvcBootConfiguration
. (the Spring-Boot specific Rest configuration class).
This has the same outward appearance as https://github.com/spring-projects/spring-boot/issues/1171, but a different root cause.
Here is an example configuration class:
@Configuration
@Slf4j
public class RestConfiguration extends RepositoryRestMvcConfiguration {
@Autowired
BeforeCreateUserValidator beforeCreateUserValidator;
@Override
protected void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener validatingListener) {
validatingListener.addValidator("beforeCreate", beforeCreateUserValidator);
}
}
Normally, I would extend RepositoryRestMvcBootConfiguration
instead of RepositoryRestMvcConfiguration
to solve this problem, but because it has default permissions it isn’t visible unless I put my class in the same package.
For now I’ve worked around this by copying the code from RepositoryRestMvcBootConfiguration
into my class, and adding the following to my app class:
@EnableAutoConfiguration(exclude= {RepositoryRestMvcAutoConfiguration.class})
I’m not sure if this is a documentation bug, or what. Most documentation online seems to tell you to extend RepositoryRestMvcConfiguration
to get custom behavior, but this seems to cause problems.
Note: I had a bunch of updates to this issue as I was debugging, it turns out I had a bug, so I’ve clarified this bug to just the relevant points now.
Issue Analytics
- State:
- Created 9 years ago
- Comments:16 (6 by maintainers)
The thing is
RepositoryRestMvcConfiguration
exposes aRepositoryRestConfiguration
which is the thing that we override to expose thespring.data.rest
properties.You should be able to override that class and still use the auto-configuration. The main difference really is that this class is in Spring Data Rest and not in Spring Boot so when you extend the one from SD Rest you basically wipe out all our customizations.
You should extend from
RepositoryRestMvcBootConfiguration
instead. We should make that class public and explain in the documentation how to use it.For now you can easily workaround the problem by adding the following code to your
RestConfiguration