0

I have one FeignClient class and I want to use MatrixVariable to pass parameters like below

@FeignClient(value = "apiService", url = "${api.url}", configuration =ApiServiceConfiguration.class)
public interface ApiServiceFeign {
    @RequestMapping(value = "/students{matrixParam}", method = RequestMethod.GET)
    StudentList getStudents(@MatrixVariable("matrixParam") Map<String,List<String>>);
}

but when I use above code it doesn't work. Feign Client can not understand the MatrixVariable. Is there any way to make this call?

Currently, I have found the temporary solution using PathVariable like below

@FeignClient(value = "apiService", url = "${api.url}", configuration =ApiServiceConfiguration.class)
public interface ApiServiceFeign {
    @RequestMapping(value = "/students;name={name};accountId={accountId}", method = RequestMethod.GET)
    StudentList getStudents(@PathVariable("name") String name,@PathVariable("accountId") Long accountId);
}

I really appreciate if any one give better solution using MatrixVariable in Feignclient

NIrav Modi
  • 6,038
  • 8
  • 32
  • 47

1 Answers1

0

You must enable the matrix variables usage in spring. That can be done by following.

Note that to enable the use of matrix variables, you must set the removeSemicolonContent property of RequestMappingHandlerMapping to false. By default it is set to true.

The MVC Java config and the MVC namespace both provide options for enabling the use of matrix variables. If you are using Java config, The Advanced Customizations with MVC Java Config section describes how the RequestMappingHandlerMapping can be customized.

In the MVC namespace, the element has an enable-matrix-variables attribute that should be set to true. By default it is set to false.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <mvc:annotation-driven enable-matrix-variables="true"/>

</beans>
Sudhakar
  • 3,104
  • 2
  • 27
  • 36