我有一个Jersey REST 2.5.1服务,通过Grizzly服务器提供服务。到目前为止一切正常。我想添加一些静态内容,这些内容也通过Grizzly提供,并从我的JAR文件中提供。所以我用 CLStaticHttpHandler
。当我访问静态资源时,例如我的 index.html
明确地(例如 http://localhost:8080/index.html
),一切正常。但是,当我尝试访问root时 http://localhost:8080
,我得到一个404.代码看起来像这样:
ObjectMapper mapper = new ObjectMapper();
// some configuration stuff here
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(mapper);
ResourceConfig resourceConfig = new ResourceConfig()
.packages("my.restapi.package")
.register(provider);
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), resourceConfig);
HttpHandler httpHandler = new CLStaticHttpHandler(HttpServer.class.getClassLoader(), "/static/");
httpServer.getServerConfiguration().addHttpHandler(httpHandler, "/");
据我调试,我可以告诉 org.glassfish.grizzly.http.server.CLStaticHttpHandler.handle(String, Request, Response)
永远不会被召唤。任何提示,我怎么能做到 index.html
可以作为默认页面访问