java - Spring Boot 2.1 中的 URI 模式匹配

标签 java spring spring-boot url-routing

随着第 5 版的推出,Spring 更改了默认的 URL 模式匹配机制 AntPathMatcherPathPattern类(class)。基于 Spring 5.1 版本的 Spring Boot 2.1 不遵循此更改,因为它仍然使用 AntPathMatcher 进行处理:

@GetMapping("/spring5/{*id}") //PathPattern implementation, compilation error
@GetMapping("/spring5/**") // AntPathMatcher implementation, works fine

有没有办法为 Spring Boot 2.1 应用程序启用 PathPattern 匹配机制?

最佳答案

Ant Matcher 将与 /spring5/** 和正常的路径模式将适用于

@GetMapping("/spring5/{*id}")
public void methodName(@PathVariable String id)

尝试添加@PathVariable,它会为你工作。

关于java - Spring Boot 2.1 中的 URI 模式匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59876623/

相关文章:

Java.util.logging。 SetLevel 对自定义 Handler 没有影响

java - JSP隐式对象和EL表达式隐式对象有什么区别?

java - Eclipse 在 Ubuntu 上一直死机

javascript - Thymeleaf - 在 Javascript 代码中迭代模型属性

java - Spring Boot Rest 响应返回 login.jsp

java - 泽西声明式链接不起作用

java - 普罗米修斯错误 : Collector already registered that provides name: http_client_requests_count

java - @Autowired & Spring 上下文层次结构

spring-boot - 如何实现多后端服务、解耦架构的SSO

java - 如何保护 Spring Boot/Spring-Data Rest 以便用户只能部分访问对象