qqi*_*ihq 11 java grizzly jersey-2.0
我有一个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, "/");
Run Code Online (Sandbox Code Playgroud)
据我所知,从调试开始,org.glassfish.grizzly.http.server.CLStaticHttpHandler.handle(String, Request, Response)
永远不会被调用.任何提示,我如何使index.html
可访问的默认页面?
经过一些浪费时间后,我觉得现在有点愚蠢,但简单的解决方案是,指定路径BASE_URI
(http://localhost:8080/api/
而不是http://localhost:8080/
).现在,在访问时/
,我得到index.html
了REST方法/api
.