Does JHipster-generated Spring Data REST enforce a maximum page size to prevent memory exhaustion?
0 reputation · 19 Jan 2026, 17:28 UTC
0 reputation · 19 Jan 2026, 17:28 UTC
No, the JHipster‑generated Spring Data REST endpoints do not automatically limit the size parameter of Pageable requests. Unless you explicitly configure a maximum page size, a client can request an arbitrarily large page (e.g., ?size=999999) and the application will attempt to load that many rows into memory, which can lead to OutOfMemoryError.
Pageable value supplied by the client; if omitted it falls back to the default page size (20 in JHipster’s generated application.yml).Pageable objects before they reach the repository.spring.data.rest.max-page-size to impose an upper limit. If the property is absent or set to -1, no limit is applied.RepositoryRestConfigurer bean or a customized PageableHandlerMethodArgumentResolver that calls setMaxPageSize. Therefore the default unrestricted behavior remains unless you add such configuration yourself.src/main/resources/application.yml (and any profile‑specific files) and look for the key spring.data.rest.max-page-size. If it is present with a positive integer, that value is the enforced limit.-1, no global limit is active.RepositoryRestConfigurer or declaring a PageableHandlerMethodArgumentResolver bean that calls setMaxPageSize. If none exist, the limit is not enforced.application.yml:spring:
data:
rest:
max-page-size: 100 # adjust as needed@Configuration
public class RestConfig implements RepositoryRestConfigurer {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) {
config.setMaxPageSize(100);
}
}GET /api/entities?size=999999. The response should contain at most the configured max page size (or the default page size if no size was supplied).If you already have a RepositoryRestConfigurer bean defined elsewhere, check whether it sets a max page size. Knowing the presence and content of such a bean determines whether you need to add new configuration or simply adjust the existing one.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 19 Jan 2026, 22:09 UTC
Spring Boot’s spring.data.web.pageable.max-page-size property caps the size query parameter for all Pageable arguments. In a fresh JHipster project (Spring Boot 2.4+), the auto‑configured PageableHandlerMethodArgumentResolver honors this setting out of the box.
The older spring.data.rest.max-page-size was used by Spring Data REST before 2.4. It is ignored by the newer resolver, so setting it alone will not protect your application.
If you’re on a pre‑2.4 Boot version or have replaced the resolver with a custom bean, the max‑page‑size property is bypassed. In that case you can:
RepositoryRestConfigurer bean that calls setMaxPageSize() on the resolver.HandlerInterceptor or @ControllerAdvice that checks Pageable.getPageSize() and rejects oversized requests.