【问题标题】:Resource handler in quarkusquarkus 中的资源处理程序
【发布时间】:2021-07-12 11:03:37
【问题描述】:

我需要一个资源处理程序来提供静态资源。我知道要提供静态资源,我应该将它们放在META-INF/resources 中。我想添加具有 URL 路径模式的资源处理程序并配置位置以提供静态资源。

【问题讨论】:

    标签: quarkus


    【解决方案1】:

    我建议调查 Quarkus 的Reactive Routes。 它们基本上允许您以更具声明性的方式注册Vert.x Route。 在你的 Route 的实现中,你可以做任何你喜欢的事情。 作为参考,this 是 Vert.x 提供静态资源的方式。

    【讨论】:

      【解决方案2】:

      根据之前的回答https://stackoverflow.com/a/68347961/8284722,解决方案可以是:

      @ApplicationScoped
      public class StaticContentDeclarativeRoute {
      
          @Route(path = "/static/*", methods = Route.HttpMethod.GET)
          void staticContent(RoutingContext rc) {
              StaticHandler.create(FileSystemAccess.RELATIVE, "content/").handle(rc);
          }
      
      }
      

      考虑路径也可以是绝对的,使用FileSystemAccess.ROOT

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-05-17
        • 2010-09-09
        • 2020-11-01
        • 1970-01-01
        • 2021-05-20
        • 2016-06-22
        • 1970-01-01
        • 2013-01-13
        相关资源
        最近更新 更多