簡體   English   中英

如何在Grizzly http服務器中設置Jersey的模板基本路徑?

[英]How to setup template base path for Jersey in Grizzly http server?

使用Apache JerseyGrizzly http服務器 ,如何設置基本模板路徑?

由於我沒有使用Servlet容器,因此我使用絕對文件路徑分配模板基本路徑。 但澤西回應了404。

以下是我的項目設置

項目目錄

src
 └─ java
      .....
 └─ resources
    └─ templates
       └─ index.mustache

申請

public class ExampleApplication extends ResourceConfig {

  public CustomTableApplication() {
    packages("com.example.app");

    setupTemplateEngine();
  }

  private void setupTemplateEngine() {
    property(MvcFeature.TEMPLATE_BASE_PATH, "/templates/");
    register(MustacheMvcFeature.class);
  }
}

控制器

@Path("/")
public class Index {

  @GET
  @Template(name = "index")
  public String index() {
    return "";
  }
}

我如何創建HttpServer

HttpServer server = new HttpServer();
NetworkListener listener = new NetworkListener("example", "localhost", 8080);
server.addListener(listener);

ServerConfiguration config = server.getServerConfiguration();
config.addHttpHandler(createJerseyHandler(), "/*");

我誤解了澤西在解析模板名稱時如何找到模板文件。

使用資源com.example.app.Index和模板基本路徑/templates

相對模板參考 @Template(name = "index")

/templates/com/example/app/Index/index.mustache

絕對模板參考 @Template(name = "/index")

/templates/index.mustache

有關詳細信息,請參閱文檔: 19.3。 絕對與相對模板參考

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM