简体   繁体   English

如何设置spring dispatcherServlet路径?

[英]How to set spring dispatcherServlet path?

I use application.properties file to set DispatcherServlet path:我使用application.properties文件来设置DispatcherServlet路径:

server.servlet.path=/api/

When I go to url /api/ , I get this exception:当我 go 到 url /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

How to set DispatcherServlet path?如何设置 DispatcherServlet 路径?

您始终可以查看Spring 属性附录以找到您想要的属性:

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

According to the application.properties docs :根据application.properties 文档

server.servlet-path=/ # Path of the main dispatcher servlet. server.servlet-path=/ # 主调度程序 servlet 的路径。

The correct key is server.servlet-path , notice the - .正确的键是server.servlet-path ,注意-

Use spring.mvc.servlet.path=/api since server.servlet.path got deprecated使用spring.mvc.servlet.path=/api因为server.servlet.path已弃用

It's spring.mvc.servlet.path now (2.3.x).现在是spring.mvc.servlet.path (2.3.x)。 Let's see when it changes again :)让我们看看它什么时候再次改变:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM