WebMvcLinkBuilder无法处理alwaysUseFullPath = true

问题描述

我遇到了与https://github.com/spring-projects/spring-hateoas/issues/102中几乎相同的问题,但是使用了更新的构建器,即WebMvcLinkBuilder

简而言之:

  • 其余的servlet这样映射到/rest/v1/*上:

      @Configuration
      @EnableWebMvc
      @ImportAutoConfiguration(ServletWebServerFactoryAutoConfiguration.class)
      public class ServletConfig implements WebMvcConfigurer {
    
          @Bean
          public ServletContextInitializer servletContextInitializer() {
              return servletContext -> {
                  // REST v1 servlet
                  AnnotationConfigWebApplicationContext restContextV2 = new AnnotationConfigWebApplicationContext();
                  restContextV2.register(RestConfig.class);
                  ServletRegistration.Dynamic restServletV2 = servletContext.addServlet("rest",new DispatcherServlet(restContextV2));
                  restServletV2.setLoadOnStartup(1);
                  restServletV2.addMapping("/rest/v1/*");
              };
          }
    
      }
    
  • alwaysUseFullPath已在RestConfig

    中启用
  • documents控制器已映射到/rest/v1/documents

然后发布到/rest/v1/documents的帖子中,我收到一个看起来像这样的链接:http://localhost:8080/rest/v1/rest/v1/documents(注意 double servlet映射)

链接至完整示例:https://github.com/artszko/spring-hateoas-links-issue

我是否配置错误,或者这实际上是一个错误?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...