Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...