Я пытаюсь развернуть REST API на основе Jersey-Spring, используя Grizzly com.sun.grizzly.http.embed.GrizzlyWebServer
. Я также хочу обслуживать статический контент, используя то же самое. Вот что у меня есть:
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();
«Адаптер Джерси» работает нормально, но я не могу получить статический контент, присутствующий в папке «webapp», для обслуживания (ошибка 404).
Структура папки моего проекта выглядит следующим образом:
GrizzlyTest
-- src
| |
| -- main
| |
| -- java
| -- resources
| |
| -- webapp
| | |
| | -- index.html
| -- spring-context.xml
|
-- pom.xml
Я ошибаюсь, указывая путь для «webapp» в строке new GrizzlyWebServer(host, port, "webapp", false);
??
Или есть ли другой способ обслуживать статический контент??