7

How we can make following configurable through .properties file?

@RequestParam(value = "page", required = false, defaultValue="0") Integer page,
@RequestParam(value = "size", required = false,defaultValue="8") Integer size,

How to make defaultValue="0" and defaultValue="8" configurable through .properties file in Spring MVC? Also how we can do it in @PageableDefault(size = 8, page = 0) ?

1 Answers1

10

@RequestParam supports placeholders syntax like ${x.y}, check documentation.

  1. Define required properties in a property file as application.properties request.defaultPageValue=0
  2. Load the property file in your servlet xml config.

    <context:property-placeholder ignore-unresolvable="true" location="/WEB-INF/application.properties"/>

  3. Use the property in requestParam

    @RequestParam(value = "page", required = false, defaultValue="${request.defaultPageValue}") Integer page,

For setting default values in Pageable, same idea use placeHolder syntax to load integers, check related SO question.

Community
  • 1
  • 1
Anudeep Gade
  • 1,365
  • 1
  • 9
  • 18
  • its perfectly working for me RequestParam, not tested Pageable, which one is not working for you ? – Anudeep Gade Sep 15 '15 at 14:45
  • Not useful to me for following public final int pageIndex = Integer.parseInt(Properties.getProperty("pagination.page.index")); public final int pageSize = Integer.parseInt(Properties.getProperty(".pagination.page.size")); @PageableDefault(size = pageIndex, page = pageSize ) Pageable pageable –  Sep 15 '15 at 15:57