How to set spring dispatcherServlet path?

Viewed 3013

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?

4 Answers

According to the application.properties docs:

server.servlet-path=/ # Path of the main dispatcher servlet.

The correct key is server.servlet-path, notice the -.

It's spring.mvc.servlet.path now (2.3.x). Let's see when it changes again :)

Use spring.mvc.servlet.path=/api since server.servlet.path got deprecated

Related