question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extending RepositoryRestMvcConfiguration prevents spring.data.rest properties from taking effect

See original GitHub issue

I 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:closed
  • Created 9 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
njwangchuancommented, Nov 30, 2016
@Configuration
public class DataRepoConfiguration extends RepositoryRestMvcConfiguration {

	@Override
	@ConfigurationProperties(prefix = "spring.data.rest")
	public RepositoryRestConfiguration config() {
		return super.config();
	}

	@Override
	protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
		//TODO
	}
}
1reaction
snicollcommented, Jan 22, 2015

The thing is RepositoryRestMvcConfiguration exposes a RepositoryRestConfiguration which is the thing that we override to expose the spring.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

@Bean
@ConfigurationProperties(prefix = "spring.data.rest")
@Override
public RepositoryRestConfiguration config() {
    return super.config();
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Data REST Reference Guide
Spring Data REST configuration is defined in a class called RepositoryRestMvcConfiguration and you can import that class into your application's ...
Read more >
Spring Data-Rest + Spring MVC - Stack Overflow
Try adding configuration hook to your RepositoryRestMvcConfiguration bean: @Configuration @Import(RepositoryRestMvcConfiguration.class) ...
Read more >
Migrating a Spring Boot application to Java 17 – the hard way
In this blog post, we update an existing Spring Boot application until we can develop new code using Java 17.
Read more >
Advanced Spring Data REST by Oliver Gierke - YouTube
Spring Data REST provides a solid foundation to build domain-driven REST webservices leveraging hypermedia. It takes away the boilerplate ...
Read more >
Creating REST service using spring-data-cassandra and ...
I am working on a POC -- creating a REST service to perform basic CRUD operations into Cassandra. I am using spring-data-cassandra and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found