Skip to content

Improve/extend Spring Data REST auto-configuration #1171

Closed

Description

@odrotbohm

@gregturn and me were discussing some simplifications to use and customize Spring Data REST and we thought these items would be good enhancements to the Boot auto-config support.

A common thing to do is to set the base URI for the exported resources. This currently requires the following dance:

@Configuration
class MyCustomConfiguration extends RepositoryRestMvcConfiguration {

  @Override
  protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
    config.setBaseUri(Uri.create("…"));
  }
}

It would be cool if Boot added a property spring.data.rest.baseUri that would allow customizing that and instead of deploying the standard RepositoryRestMvcConfiguration deploy the sub-type that applies the property.

As probably becoming obvious from the example above, the shown method is the key one to apply customizations to Spring Data REST. It would be cool if Boot could ease that as follows:

@EnableAutoConfiguration
class Application {

  public static void main(String... args) {
    SpringApplication.run(Application.class, args);
  }

  @Bean RepositoryRestConfiguration restConfig() {
    RepositoryRestConfiguration config = new RepositoryRestConfiguration();
    // customizations go here
    return config;
  }
}

So if Boot picked up a RepositoryRestConfiguration bean in the suer configuration and effectively transferred to the template method of RepositoryRestMvcConfiguration.

Activity

  1. snicoll commented on Jun 26, 2014

    @snicoll
    Member

    Having used that lately, I can only say 👍

  2. self-assigned this
    on Jun 26, 2014
  3. added this to the 1.2.0 milestone on Jun 26, 2014
  4. modified the milestones: 1.1.4, 1.2.0 on Jul 3, 2014
  5. odrotbohm commented on Jul 3, 2014

    @odrotbohm
    MemberAuthor

    @markfisher That one, too?

  6. markfisher commented on Jul 3, 2014

    @markfisher

    Sorry @olivergierke - that was a result of an unintentional mass-edit. I believe I have reopened all of the issues that I had mistakenly closed.

  7. odrotbohm commented on Jul 3, 2014

    @odrotbohm
    MemberAuthor

    No worries :).

  8. removed this from the 1.1.4 milestone on Jul 3, 2014
  9. marceloverdijk commented on Aug 8, 2014

    @marceloverdijk

    +1 for spring.data.rest.baseUri

  10. added this to the 1.2.0 milestone on Aug 13, 2014
  11. snicoll commented on Aug 28, 2014

    @snicoll
    Member

    Any property of the RepositoryRestConfiguration can now be customized through the environment using the spring.data.rest prefix. So spring.data.rest.baseUri does work obviously but also spring.data.rest.maxPageSize for instance.

  12. jbcpollak commented on Sep 23, 2014

    @jbcpollak

    I am having trouble getting this to work.

    I upgraded to 1.2.0.M1 like this:

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.2.0.M1</version>
        </parent>
    

    And set this in my properties file:
    spring.data.rest.baseUri=/data

    but it does not seem to work, the default uri (/) seems to remain in effect.

    Am I doing something wrong?

  13. wilkinsona commented on Sep 23, 2014

    @wilkinsona
    Member

    Yes, I suspect you are, although I can't tell from the information you've provided. There's a test for the behaviour that you're trying to use which passes.

    Perhaps you have your own RepositoryRestMvcConfiguration bean that's being used in place of Boot's? If that's not the case, you might like to post a question on StackOverflow with some more details on your app and its configuration.

  14. mraible commented on Oct 8, 2014

    @mraible

    I tried setting this property on my 1.2.0.M1 project today as well and it doesn't work.

    In my application.yml:

    spring:
      data:
        rest:
          baseUri: /api
    

    My data REST services are still available at / rather than /api.

  15. mraible commented on Oct 8, 2014

    @mraible

    Using the following does work:

    @Configuration
    @Import(RepositoryRestMvcConfiguration.class)
    public class RestDataConfig extends RepositoryRestMvcConfiguration {
    
        @Override
        protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
            super.configureRepositoryRestConfiguration(config);
            try {
                config.setBaseUri(new URI("/api"));
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    

    FWIW, the endpoints published with @RepositoryRestResource aren't picked up by Swagger as endpoints.

  16. snicoll commented on Oct 9, 2014

    @snicoll
    Member

    Matt, could you please run your app with the --debug flag and check the auto configuration report (if you have actuator, you can hit /autoconfig).

    I am interested in the match content for RepositoryRestMvcAutoConfiguration. Thanks!

  17. wilkinsona commented on Oct 9, 2014

    @wilkinsona
    Member

    I can reproduce this in a Spring Data REST app I've been working on. I've opened #1675.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions