在 spring 启动时删除对“/”的直接访问
Remove direct access to "/" on spring boot
我有一个 spring 启动应用程序,其中我只定义了 2 个端点。
@RequestMapping(value = "/getAllFeatures", method = RequestMethod.GET)
@Cacheable("features")
public ResponseEntity<?> getAllFeatures() {
...
}
@RequestMapping(name = "/getFeatureStatus", method = RequestMethod.GET)
@Cacheable("features")
public ResponseEntity<?> getFeatureStatus(@RequestParam(value = "groupName", required = false) String groupName,
@RequestParam(value = "featureName", required = false) String featureName) {
...
}
并且我已经将上下文定义为 server.context-path=/abc
当我在 /abc/ 上执行 GET 调用时,应用程序给了我一个有效的响应。因为我从来没有在我的休息控制器中映射过“/”。关于如何阻止对“/”的请求的任何想法。此外,此应用程序不需要任何类型的 spring 安全性。
应该是
@RequestMapping(path= "/getFeatureStatus"....)
而不是
@RequestMapping(name = "/getFeatureStatus"....)
name 属性只是为此映射指定一个名称。
有时“/”端点会映射到资源文件夹的 index.html 文件。
这个文件存在吗?
您还需要使用 @RestController 注释您的 class。
我有一个 spring 启动应用程序,其中我只定义了 2 个端点。
@RequestMapping(value = "/getAllFeatures", method = RequestMethod.GET)
@Cacheable("features")
public ResponseEntity<?> getAllFeatures() {
...
}
@RequestMapping(name = "/getFeatureStatus", method = RequestMethod.GET)
@Cacheable("features")
public ResponseEntity<?> getFeatureStatus(@RequestParam(value = "groupName", required = false) String groupName,
@RequestParam(value = "featureName", required = false) String featureName) {
...
}
并且我已经将上下文定义为 server.context-path=/abc
当我在 /abc/ 上执行 GET 调用时,应用程序给了我一个有效的响应。因为我从来没有在我的休息控制器中映射过“/”。关于如何阻止对“/”的请求的任何想法。此外,此应用程序不需要任何类型的 spring 安全性。
应该是
@RequestMapping(path= "/getFeatureStatus"....)
而不是
@RequestMapping(name = "/getFeatureStatus"....)
name 属性只是为此映射指定一个名称。
有时“/”端点会映射到资源文件夹的 index.html 文件。 这个文件存在吗? 您还需要使用 @RestController 注释您的 class。