4
With Apache Jersey and Grizzly http server,我該如何設置基礎模板路徑?如何在澤西灰熊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(), "/*");
PLS。嘗試註冊HttpHandler,如:config.addHttpHandler(createJerseyHandler(),「/ *」); – alexey
createJerseyHandler()返回什麼?有鬍子的HTTPHandler嗎? – sharky