如何设置spring dispatcherServlet路径?

时间:2017-09-30 09:07:35

标签: java spring

我使用 application.properties 文件来设置DispatcherServlet路径:

server.servlet.path=/api/

当我转到网址/api/时,我遇到了这个例外:

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

如何设置DispatcherServlet路径?

3 个答案:

答案 0 :(得分:1)

您始终可以查看the Spring properties appendix以查找所需的媒体资源:

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

答案 1 :(得分:1)

根据 application.properties docs

  

server.servlet-path = /#主调度程序servlet的路径。

正确的密钥为server.servlet-path,请注意-

答案 2 :(得分:0)

现在是spring.mvc.servlet.path(2.3.x)。让我们看看它何时再次发生变化:)