spring.data.rest.max-page-size does not seem to work?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 05:07:44

问题


Under Boot 1.3.0.M5 i use in application.properties

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

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

does not work.

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

will work.

I still think this is strange behaviour.

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 coud find private int maxPageSize = 1000; which explains why it changed to 1000. I havn'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 I haven't found a way so far.


回答1:


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.




回答2:


I just tried that - I think your expectation is correct - it sets the maximum limit of a page.

But I think your property name is incorrect - try this:

spring.data.rest.maxPageSize=10

See here for documentation: http://docs.spring.io/spring-data/rest/docs/2.4.0.RELEASE/reference/html/#_changing_other_spring_data_rest_properties




回答3:


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



来源:https://stackoverflow.com/questions/33675349/spring-data-rest-max-page-size-does-not-seem-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!