spring.data.rest.max-page-size does not seem to be working

8

Under Spring Boot 1.3.0.M5 I'm using

spring.data.rest.max-page-size=10

in application.properties.

But I still can set the size to 40 in a URL and get a correct response. For example : http://localhost:8080/cine20-spring/api/films?page=0&size=40&sort=title,asc

will give me back 40 films

So what is the use of this parameter ?

Update test with Spring-Boot 1.4.2

There is still a problem : By default WITHOUT the dependencies spring-boot-starter-data-rest , the max-page-size is set to 2000 by default and changing the max-page-size value won't work :

spring.data.rest.max-page-size=0x7fffffff

Adding spring-boot-starter-data-rest => the max-page-size is now set to 1000 by default , then changing the param max-page-size will work:

spring.data.rest.max-page-size=0x7fffffff

I still believe, this is strange behavior.

In : https://github.com/spring-projects/spring-data-rest/blob/master/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/RepositoryRestConfiguration.java

You could find private int maxPageSize = 1000; which explains why it changed to 1000. I haven't found, why it is set to 2000 from the start though.

I would like to set the param spring.data.rest.max-page-size freely without the need to add the dependency : spring-boot-starter-data-rest, but unfortunately I haven't found a way so far.

spring-data-rest
asked on Stack Overflow Nov 12, 2015 by Gauthier Peel • edited Feb 13, 2021 by Muhammad Waqas Dilawar

4 Answers

13

This was somewhat of a gotcha for me. I think the easiest solution is using configuration properties instead of code. So this is what I found and what worked for me.

If you are using a Pageable in a @RestController then you can set it using property spring.data.web.pageable.max-page-size.

If you are using a Pageable in a @RepositoryRestResource then you can set it using property spring.data.rest.max-page-size.

answered on Stack Overflow Oct 30, 2018 by Rafiek • edited Nov 8, 2018 by Rafiek
1

I am able to do this on Spring Boot 2.1.x and 2.3.3 to override the default Pageable max page size of 2000.

@Configuration
public class PageableConfig {

    @Bean
    PageableHandlerMethodArgumentResolverCustomizer pageableResolverCustomizer() {
        return pageableResolver -> pageableResolver.setMaxPageSize(9999);
    }
}

Adding either of these spring.data.web.pageable.max-page-size (spring.data.web.pageable.maxPageSize) or spring.data.rest.max-page-size (spring.data.rest.maxPageSize) properties in application.properties did not work for me. i.e.

# these properties did not allow me to override the default of 2000 for maxPageSize
spring.data.web.pageable.max-page-size=9999
spring.data.rest.max-page-size=9999

For further details, kindly visit https://github.com/spring-projects/spring-boot/issues/14413 and this https://jira.spring.io/browse/DATAREST-1290

See related SO: Set default page size for JPA Pageable Object post: Set default page size for JPA Pageable Object

answered on Stack Overflow Sep 22, 2020 by Neon • edited Feb 15, 2021 by Jin Lee
0

Worked for me only with config enforced through code:

@Configuration
public class CustomizedRestMvcConfiguration extends RepositoryRestMvcConfiguration
{
  @Override
  public RepositoryRestConfiguration config() {
    RepositoryRestConfiguration config = super.config();
    config.setMaxPageSize(10000);
    return config;
  }
}

http://docs.spring.io/spring-data/rest/docs/2.4.0.RELEASE/reference/html/#_changing_the_base_uri

answered on Stack Overflow Sep 23, 2016 by Dmitry
0

Try this will work in properties add this line

spring.data.rest.default-page-size=1000
answered on Stack Overflow Dec 1, 2020 by gharbiMotez • edited Dec 1, 2020 by Amit Verma

User contributions licensed under CC BY-SA 3.0