Это вопрос о том, как лучше отделять код для встраивания пристани из кода для проводки до сервлетов.Бегущая война с причалом + guice
Я пытаюсь адаптировать this sample code так, что я получу бегущую войну, т. Е. Военный файл, который я могу занести в существующий контейнер Jetty, или запустить автономный с помощью команды типа java -jar webapp-runnable.war
. Образец кода принадлежит этим двум блогам: No.1, No.2.
Я следовал GuiceServlet manual и создал web.xml
и GuiceServletContextListener
(смотри ниже), но они, кажется, не поймите меня очень далеко с mvn jetty:run
; Когда я пытаюсь запустить mvn jetty:run
, я получаю следующее сообщение об ошибке:
[main] DEBUG org.eclipse.jetty.util.log - Logging to Logger[org.eclipse.jetty.util.log] via org.eclipse.jetty.util.log.Slf4jLog
WARN:oejw.WebAppContext:main: Failed startup of context [email protected]{/,file:/[...]/src/main/webapp/,STARTING}{file:/[...]/src/main/webapp/}
com.google.inject.ConfigurationException: Guice configuration errors:||1) Explicit bindings are required and com.google.inject.servlet.InternalServletModule$BackwardsCompatibleServletContextProvider is not explicitly bound.| while locating com.google.inject.servlet.InternalServletModule$BackwardsCompatibleServletContextProvider||1 error
at [stack strace clipped]
Вот мой код. Как упоминалось ранее, я начал с this repo on github.
1) Я извлек анонимный внутренний класс типа AbstractModule из com.teamlazerbeez.http.HttpServerMain
и поместить его в новый класс com.teamlazerbeez.http.HttpServerModule
. Этот класс теперь создается при создании Injector Guice in HttpServerMain
(l36).
2) Мои web.xml
:
<?xml version="1.0" ?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="false"
version="3.0">
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.teamlazerbeez.http.GuiceServletConfig</listener-class>
</listener>
</web-app>
3) Мои com.teamlazerbeez.http.GuiceServletConfig
:
public class GuiceServletConfig extends GuiceServletContextListener {
@Override
protected Injector getInjector() {
//I know this code not come close to doing what I want, but I just don't know where to start
return Guice.createInjector(new HttpServerModule());
}
}
Мой вопрос: Как реорганизовать метод HttpServerMain
main
и HttpServerModule
в такой что описанный ими процесс установки становится usabl e к моему GuiceServletConfig
? И что должно быть GuiceServletConfig
похоже, чтобы это сработало?