On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo Luzzardi de Carvalho 
wrote:
>
> java.lang.NullPointerException
>
>         at com.google.inject.persist.jpa.JpaPersistService.begin(
> JpaPersistService.java:77)
>
>         at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(
> JpaLocalTxnInterceptor.java:53)
>
>         at com.app.guice.AppGuiceServletContextListener.contextInitialized
> (AppGuiceServletContextListener.java:60)
>
>         at org.mortbay.jetty.handler.ContextHandler.startContext(
> ContextHandler.java:548)
>
>         at org.mortbay.jetty.servlet.Context.startContext(Context.java:136
> )
>
>         at org.mortbay.jetty.webapp.WebAppContext.startContext(
> WebAppContext.java:1234)
>
>         at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler
> .java:517)
>
>         at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.
> java:460)
>
>         at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle
> .java:50)
>
>         at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper
> .java:130)
>
>         at org.mortbay.jetty.Server.doStart(Server.java:222)
>
>         at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle
> .java:50)
>
>         at com.app.Start.start(Start.java:126)
>
>         at com.app.Start.main(Start.java:194)
>
> Follows my servlet context listener:
>
> package com.app.guice;
>
>
> import javax.servlet.ServletContext;
>
> import javax.servlet.ServletContextEvent;
>
>
> import org.mortbay.jetty.Server;
>
>
> import com.app.setup.AppLifeCycle;
>
> import com.google.inject.Guice;
>
> import com.google.inject.Injector;
>
> import com.google.inject.Provides;
>
> import com.google.inject.Singleton;
>
> import com.google.inject.servlet.GuiceServletContextListener;
>
>
> public class AppGuiceServletContextListener extends 
> GuiceServletContextListener {
>
>
> private AppLifeCycle appLifeCycle;
>
>
> private Server server;
>
>
> private ServletContext servletContext;
>
>
> private Injector injector;
>
>
> public AppGuiceServletContextListener(Server server) {
>
> super();
>
> this.server = server;
>
> }
>
>
> @Override
>
> public void contextDestroyed(ServletContextEvent ctx) {
>
> super.contextDestroyed(ctx);
>
> if (appLifeCycle != null) {
>
> appLifeCycle.destroy();
>
> }
>
> }
>
>
> @Override
>
> public void contextInitialized(ServletContextEvent servletContextEvent) {
>
> servletContext = servletContextEvent.getServletContext();
>
> super.contextInitialized(servletContextEvent);
>
>
> appLifeCycle = injector.getInstance(AppLifeCycle.class);
>
> appLifeCycle.init(servletContext);
>
> }
>
>
> @Provides
>
> @Singleton
>
> Server provideServer(Injector injector) {
>
> final Server server = this.server;
>
> injector.injectMembers(server);
>
> return server;
>
> }
>
>
> @Override
>
> protected Injector getInjector() {
>
> System.out.println(servletContext);
>
> if (injector == null)
>
> injector = Guice.createInjector(new MainModule(String.format(
> "%s/WEB-INF/app", servletContext.getRealPath("/")), servletContext));
>
> return injector;
>
> }
>
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/4df2e8df-81e9-4523-80c6-b4c1cfafa763%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to