'How to set spring dispatcherServlet path?
I use application.properties file to set DispatcherServlet
path:
server.servlet.path=/api/
When I go to url /api/
, I get this exception:
Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'servlet[path]' of bean class [org.springframework.boot.autoconfigure.web.ServerProperties]: Bean property 'servlet[path]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:731)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:948)
... 59 common frames omitted
How to set DispatcherServlet path?
Solution 1:[1]
You always can look over the Spring properties appendix to find a property you want:
server.servlet-path=/ # Path of the main dispatcher servlet.
Solution 2:[2]
According to the application.properties docs:
server.servlet-path=/ # Path of the main dispatcher servlet.
The correct key is server.servlet-path
, notice the -
.
Solution 3:[3]
It's spring.mvc.servlet.path
now (2.3.x). Let's see when it changes again :)
Solution 4:[4]
Use spring.mvc.servlet.path=/api
since server.servlet.path
got deprecated
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andrew Tobilko |
Solution 2 | |
Solution 3 | Hans Westerbeek |
Solution 4 | Eduardo Vilaça |