5
我试图使用Grizzly的com.sun.grizzly.http.embed.GrizzlyWebServer
部署基于Jersey-Spring的REST API。我也想使用相同的静态内容。以下是我有:GrizzlyWebServer + Spring + Jersey +从JAR内提供静态内容
String host = "localhost";
int port = 8081;
// For jersey + Spring
ServletAdapter jAdapter = new ServletAdapter("jersey");
jAdapter.setContextPath("/api");
jAdapter.setServletInstance(new SpringServlet());
jAdapter.addContextParameter("contextConfigLocation", "classpath:spring-context.xml");
jAdapter.addServletListener("org.springframework.web.context.ContextLoaderListener");
jAdapter.addServletListener("org.springframework.web.context.request.RequestContextListener");
// create GrizzlyWebServer
GrizzlyWebServer grizzlyServer = new GrizzlyWebServer(host, port, "webapp", false);
// add jersey adapter
grizzlyServer.addGrizzlyAdapter(jAdapter, new String[]{"/api"});
// start server
grizzlyServer.start();
System.out.println("Start running server(host: " + host + ",port: " + Integer.toString(port));
System.out.println("Press any key to stop the server.");
// hang on
System.in.read();
// stop
grizzlyServer.stop();
的“泽西适配器”工作正常,但我不能以获取静态内容出现在“Web应用程序”文件夹送达(404错误)。
我的项目文件夹结构如下:
GrizzlyTest
-- src
| |
| -- main
| |
| -- java
| -- resources
| |
| -- webapp
| | |
| | -- index.html
| -- spring-context.xml
|
-- pom.xml
上午我在行new GrizzlyWebServer(host, port, "webapp", false);
提供“Web应用程序”的路径犯了一个错误?
或者,有没有其他的方式来提供静态内容?
感谢阿列克谢。我有一个关于来自jar的静态资源请求认证的问题,所以通过CLStaticHttpHandler与StaticHttpHandler。这是未经证实的,但它看起来认证不适用于前者,但适用于后者? 'WebappContext'中的这一行可以解释为:'if(!(h instanceof StaticHttpHandler))'(grizzly-http-servlet-2.3.17.jar)。思考?谢谢。 – user598656
好吧,从你发现它看起来可能会有一些问题。你可以请。在github上共享测试用例 - 对我来说更容易进行双重检查。 – alexey