Discussion:
NullPointerException in JpaPersistService
Diogo Luzzardi de Carvalho
2017-12-01 19:27:04 UTC
Permalink
The following exception is ocorring for me:

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)

Follows my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://java.sun.com/xml/ns/persistence"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/persistence

http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"

version="1.0">



<!-- A JPA Persistence Unit -->

<persistence-unit name="persistence.unit"

transaction-type="RESOURCE_LOCAL">

<provider>org.hibernate.jpa.HibernatePersistenceProvider</
provider>



<!-- JPA entities must be registered here -->

<!--<class>com.wideplay.warp.jpa.JpaTestEntity</class> -->

</persistence-unit>



</persistence>

follows the configuration code:

persistModule = new JpaPersistModule(PERSISTENCE_UNIT_NAME);

install(persistModule);

bind(org.hibernate.Session.class).toProvider(new SessionProvider());

filter("/*").through(PersistFilter.class);


can anyone point me what I'm doing wrong?

regards
Diogo
--
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/fd020b11-2a91-4656-9c49-6f5b0fef744e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2017-12-01 21:44:36 UTC
Permalink
Can you please give more of the stack trace (all of it).
Because the cause of this NPE is different depending on where the call
comes from.
Post by Diogo Luzzardi de Carvalho
|
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)
|
|
<?xmlversion="1.0"encoding="UTF-8"?>
<persistencexmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<!-- A JPA Persistence Unit -->
<persistence-unitname="persistence.unit"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- JPA entities must be registered here -->
<!--<class>com.wideplay.warp.jpa.JpaTestEntity</class> -->
</persistence-unit>
</persistence>
|
|
persistModule=newJpaPersistModule(PERSISTENCE_UNIT_NAME);
install(persistModule);
bind(org.hibernate.Session.class).toProvider(newSessionProvider());
filter("/*").through(PersistFilter.class);
|
can anyone point me what I'm doing wrong?
regards
Diogo
--
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
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/fd020b11-2a91-4656-9c49-6f5b0fef744e%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/fd020b11-2a91-4656-9c49-6f5b0fef744e%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/0f20958d-05f7-e323-6a3d-42ef2d908f39%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Diogo Luzzardi de Carvalho
2017-12-01 22:18:46 UTC
Permalink
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.eckertcaine.bridge.guice.BridgeGuiceServletContextListener.
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.eckertcaine.bridge.Start.start(Start.java:126)

at com.eckertcaine.bridge.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() {

if (injector == null)

injector = Guice.createInjector(new MainModule(
String.format("%s/WEB-INF/app", servletContext.getRealPath("/")),
servletContext));

return injector;

}

}

the line that points the error on the context listener is appLifeCycle.init(
servletContext);
Post by Stephan Classen
Can you please give more of the stack trace (all of it).
Because the cause of this NPE is different depending on where the call
comes from.
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)
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
<http://www.google.com/url?q=http%3A%2F%2Fjava.sun.com%2Fxml%2Fns%2Fpersistence&sa=D&sntz=1&usg=AFQjCNFVn-Ui0kpX_x57k_rRpCqNI5wg3A>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<http://www.w3.org/2001/XMLSchema-instance>
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<!-- A JPA Persistence Unit -->
<persistence-unit name="persistence.unit"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</
provider>
<!-- JPA entities must be registered here -->
<!--<class>com.wideplay.warp.jpa.JpaTestEntity</class> -->
</persistence-unit>
</persistence>
persistModule = new JpaPersistModule(PERSISTENCE_UNIT_NAME);
install(persistModule);
bind(org.hibernate.Session.class).toProvider(new SessionProvider());
filter("/*").through(PersistFilter.class);
can anyone point me what I'm doing wrong?
regards
Diogo
--
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
<javascript:>.
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/fd020b11-2a91-4656-9c49-6f5b0fef744e%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/fd020b11-2a91-4656-9c49-6f5b0fef744e%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/5e2af91c-af64-4b65-8f72-bf4e74499ff1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Diogo Luzzardi de Carvalho
2017-12-01 22:25:57 UTC
Permalink
On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo Luzzardi de Carvalho
Post by Diogo Luzzardi de Carvalho
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)
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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.
Stephan Classen
2017-12-01 22:42:47 UTC
Permalink
A second cause could be that the PersistenceService has not been started
yet.
The persistence service is started by the PersistFiler.init() method.

Unfortunately there is no way of checking if the PersistanceService is
already started. And trying to start it twice will cause an exception
the be thrown.


So my advice:
Make sure to delay the accessing of the DB until after the
PersistFiler.init() method and wrap your code in a UnitOfWork.
The simplest trick is to register another ServletFilter after the
PersistFilter and place your code in the init() method of this filter...


You may also have a look at Onami Persist which is an alternative
Post by Diogo Luzzardi de Carvalho
On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo Luzzardi de
|
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)
|
|
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);
returnserver;
}
@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));
returninjector;
}
}
|
--
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
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
<https://groups.google.com/d/msgid/google-guice/4df2e8df-81e9-4523-80c6-b4c1cfafa763%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/4555d357-8f80-23c7-f770-8ff83bd1f0ec%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Diogo Luzzardi de Carvalho
2017-12-04 15:22:22 UTC
Permalink
Hi,

I tried both of your solutions, and the nullpointer keeps happen. Also I
debug the application and I installed the JpaPersistModule before I try to
run the code when the exception happens.

regards
Diogo
Post by Stephan Classen
A second cause could be that the PersistenceService has not been started
yet.
The persistence service is started by the PersistFiler.init() method.
Unfortunately there is no way of checking if the PersistanceService is
already started. And trying to start it twice will cause an exception the
be thrown.
Make sure to delay the accessing of the DB until after the
PersistFiler.init() method and wrap your code in a UnitOfWork.
The simplest trick is to register another ServletFilter after the
PersistFilter and place your code in the init() method of this filter...
You may also have a look at Onami Persist which is an alternative
On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo Luzzardi de
Post by Diogo Luzzardi de Carvalho
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)
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)
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
<javascript:>.
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
<https://groups.google.com/d/msgid/google-guice/4df2e8df-81e9-4523-80c6-b4c1cfafa763%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/643a15e6-bbaa-4f9a-ab2e-deaea5461f77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2017-12-04 15:24:06 UTC
Permalink
Is this an open source project?
If sou you could point me to the repo and I can have a look.
Hi,
I tried both of your solutions, and the nullpointer keeps happen. Also
I debug the application and I installed the JpaPersistModule before I
try to run the code when the exception happens.
regards
Diogo
A second cause could be that the PersistenceService has not been
started yet.
The persistence service is started by the PersistFiler.init() method.
Unfortunately there is no way of checking if the
PersistanceService is already started. And trying to start it
twice will cause an exception the be thrown.
Make sure to delay the accessing of the DB until after the
PersistFiler.init() method and wrap your code in a UnitOfWork.
The simplest trick is to register another ServletFilter after the
PersistFilter and place your code in the init() method of this filter...
You may also have a look at Onami Persist which is an alternative
Post by Diogo Luzzardi de Carvalho
On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo Luzzardi
|
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)
|
|
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);
returnserver;
}
@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));
returninjector;
}
}
|
--
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,
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice
<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
<https://groups.google.com/d/msgid/google-guice/4df2e8df-81e9-4523-80c6-b4c1cfafa763%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
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
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/643a15e6-bbaa-4f9a-ab2e-deaea5461f77%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/643a15e6-bbaa-4f9a-ab2e-deaea5461f77%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/cf99a53e-8f85-c6a1-bc95-2ae2d5ca857e%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Diogo Luzzardi de Carvalho
2017-12-04 15:58:13 UTC
Permalink
Unfortunately it is not. I notice that when I change my code to do the
following:
injector = Guice.createInjector(new
MainModule(String.format("%s/WEB-INF/app",
getServletContext().getRealPath("/")), getServletContext()));
UnitOfWork unitOfWork = injector.getInstance(UnitOfWork.class);
System.out.println(unitOfWork);
unitOfWork.begin();
try {
appLifeCycle = injector.getInstance(AppLifeCycle.class);
appLifeCycle.init(getServletContext());
} finally {
unitOfWork.end();
}

return injector;

The injector was able to inject the UnitOfWork but when I call the method
unitOfWork.begin() the exception occurs at line 77 of the JpaPersistService.
Post by Stephan Classen
Is this an open source project?
If sou you could point me to the repo and I can have a look.
Hi,
I tried both of your solutions, and the nullpointer keeps happen. Also I
debug the application and I installed the JpaPersistModule before I try to
run the code when the exception happens.
regards
Diogo
Post by Stephan Classen
A second cause could be that the PersistenceService has not been started
yet.
The persistence service is started by the PersistFiler.init() method.
Unfortunately there is no way of checking if the PersistanceService is
already started. And trying to start it twice will cause an exception the
be thrown.
Make sure to delay the accessing of the DB until after the
PersistFiler.init() method and wrap your code in a UnitOfWork.
The simplest trick is to register another ServletFilter after the
PersistFilter and place your code in the init() method of this filter...
You may also have a look at Onami Persist which is an alternative
On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo Luzzardi de
Post by Diogo Luzzardi de Carvalho
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)
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)
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
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
<https://groups.google.com/d/msgid/google-guice/4df2e8df-81e9-4523-80c6-b4c1cfafa763%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
<javascript:>.
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/643a15e6-bbaa-4f9a-ab2e-deaea5461f77%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/643a15e6-bbaa-4f9a-ab2e-deaea5461f77%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/5bd6aa1d-2efc-453c-ba78-707bc1e74043%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2017-12-04 16:03:55 UTC
Permalink
This is what I mentioned before.

You cannot use any of the JPA stuff until PersistService.start() has
been called.
This will be called by the PersistFilter.init().
So you have to wait with the appLifeCycle.init() until after the init()
method of PersistFilter
Unfortunately it is not. I notice that when I change my code to do the
|
injector = Guice.createInjector(new
MainModule(String.format("%s/WEB-INF/app",
getServletContext().getRealPath("/")), getServletContext()));
UnitOfWork unitOfWork = injector.getInstance(UnitOfWork.class);
System.out.println(unitOfWork);
unitOfWork.begin();
try {
appLifeCycle = injector.getInstance(AppLifeCycle.class);
appLifeCycle.init(getServletContext());
} finally {
unitOfWork.end();
}
return injector;
|
 The injector was able to inject the UnitOfWork but when I call the
method unitOfWork.begin() the exception occurs at line 77 of the
JpaPersistService.
Is this an open source project?
If sou you could point me to the repo and I can have a look.
Hi,
I tried both of your solutions, and the nullpointer keeps happen.
Also I debug the application and I installed the JpaPersistModule
before I try to run the code when the exception happens.
regards
Diogo
A second cause could be that the PersistenceService has not
been started yet.
The persistence service is started by the PersistFiler.init() method.
Unfortunately there is no way of checking if the
PersistanceService is already started. And trying to start it
twice will cause an exception the be thrown.
Make sure to delay the accessing of the DB until after the
PersistFiler.init() method and wrap your code in a UnitOfWork.
The simplest trick is to register another ServletFilter after
the PersistFilter and place your code in the init() method of
this filter...
You may also have a look at Onami Persist which is an
Post by Diogo Luzzardi de Carvalho
On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo
|
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)
|
|
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);
returnserver;
}
@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));
returninjector;
}
}
|
--
You received this message because you are subscribed to the
Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails
Visit this group at
https://groups.google.com/group/google-guice
<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
<https://groups.google.com/d/msgid/google-guice/4df2e8df-81e9-4523-80c6-b4c1cfafa763%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
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,
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice
<https://groups.google.com/group/google-guice>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/643a15e6-bbaa-4f9a-ab2e-deaea5461f77%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/643a15e6-bbaa-4f9a-ab2e-deaea5461f77%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
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
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/5bd6aa1d-2efc-453c-ba78-707bc1e74043%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/5bd6aa1d-2efc-453c-ba78-707bc1e74043%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/3f726572-a1e5-6b51-643c-25a21c9eea4d%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Diogo Luzzardi de Carvalho
2017-12-04 16:43:33 UTC
Permalink
humm, at moment I call the appLifeCycle.init() the PersistFilter is already
configured in the application because it is configured at the MainModule
class configure method. There is any other way to make the persistService
to start?
Post by Stephan Classen
This is what I mentioned before.
You cannot use any of the JPA stuff until PersistService.start() has been
called.
This will be called by the PersistFilter.init().
So you have to wait with the appLifeCycle.init() until after the init()
method of PersistFilter
Unfortunately it is not. I notice that when I change my code to do the
injector = Guice.createInjector(new
MainModule(String.format("%s/WEB-INF/app",
getServletContext().getRealPath("/")), getServletContext()));
UnitOfWork unitOfWork = injector.getInstance(UnitOfWork.class);
System.out.println(unitOfWork);
unitOfWork.begin();
try {
appLifeCycle = injector.getInstance(AppLifeCycle.class);
appLifeCycle.init(getServletContext());
} finally {
unitOfWork.end();
}
return injector;
The injector was able to inject the UnitOfWork but when I call the method
unitOfWork.begin() the exception occurs at line 77 of the JpaPersistService.
Post by Stephan Classen
Is this an open source project?
If sou you could point me to the repo and I can have a look.
Hi,
I tried both of your solutions, and the nullpointer keeps happen. Also I
debug the application and I installed the JpaPersistModule before I try to
run the code when the exception happens.
regards
Diogo
Post by Stephan Classen
A second cause could be that the PersistenceService has not been started
yet.
The persistence service is started by the PersistFiler.init() method.
Unfortunately there is no way of checking if the PersistanceService is
already started. And trying to start it twice will cause an exception the
be thrown.
Make sure to delay the accessing of the DB until after the
PersistFiler.init() method and wrap your code in a UnitOfWork.
The simplest trick is to register another ServletFilter after the
PersistFilter and place your code in the init() method of this filter...
You may also have a look at Onami Persist which is an alternative
On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo Luzzardi de
Post by Diogo Luzzardi de Carvalho
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)
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)
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
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
<https://groups.google.com/d/msgid/google-guice/4df2e8df-81e9-4523-80c6-b4c1cfafa763%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
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/643a15e6-bbaa-4f9a-ab2e-deaea5461f77%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/643a15e6-bbaa-4f9a-ab2e-deaea5461f77%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
<javascript:>.
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/5bd6aa1d-2efc-453c-ba78-707bc1e74043%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/5bd6aa1d-2efc-453c-ba78-707bc1e74043%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/a86f2bcc-26b6-499a-97b3-ba28de701295%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2017-12-11 12:30:45 UTC
Permalink
Did you make any progress on this issue?
humm, at moment I call the appLifeCycle.init() the PersistFilter is
already configured in the application because it is configured at the
MainModule class configure method. There is any other way to make the
persistService to start?
This is what I mentioned before.
You cannot use any of the JPA stuff until PersistService.start()
has been called.
This will be called by the PersistFilter.init().
So you have to wait with the appLifeCycle.init() until after the
init() method of PersistFilter
Unfortunately it is not. I notice that when I change my code to
|
injector = Guice.createInjector(new
MainModule(String.format("%s/WEB-INF/app",
getServletContext().getRealPath("/")), getServletContext()));
UnitOfWork unitOfWork = injector.getInstance(UnitOfWork.class);
System.out.println(unitOfWork);
unitOfWork.begin();
try {
appLifeCycle = injector.getInstance(AppLifeCycle.class);
appLifeCycle.init(getServletContext());
} finally {
unitOfWork.end();
}
return injector;
|
 The injector was able to inject the UnitOfWork but when I call
the method unitOfWork.begin() the exception occurs at line 77 of
the JpaPersistService.
Is this an open source project?
If sou you could point me to the repo and I can have a look.
Hi,
I tried both of your solutions, and the nullpointer keeps
happen. Also I debug the application and I installed the
JpaPersistModule before I try to run the code when the
exception happens.
regards
Diogo
A second cause could be that the PersistenceService has
not been started yet.
The persistence service is started by the
PersistFiler.init() method.
Unfortunately there is no way of checking if the
PersistanceService is already started. And trying to
start it twice will cause an exception the be thrown.
Make sure to delay the accessing of the DB until after
the PersistFiler.init() method and wrap your code in a
UnitOfWork.
The simplest trick is to register another ServletFilter
after the PersistFilter and place your code in the
init() method of this filter...
You may also have a look at Onami Persist which is an
Post by Diogo Luzzardi de Carvalho
On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo
|
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)
|
|
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);
returnserver;
}
@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));
returninjector;
}
}
|
--
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
To post to this group, send email to
Visit this group at
https://groups.google.com/group/google-guice
<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
<https://groups.google.com/d/msgid/google-guice/4df2e8df-81e9-4523-80c6-b4c1cfafa763%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit
https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the
Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails
Visit this group at
https://groups.google.com/group/google-guice
<https://groups.google.com/group/google-guice>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/643a15e6-bbaa-4f9a-ab2e-deaea5461f77%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/643a15e6-bbaa-4f9a-ab2e-deaea5461f77%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
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,
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice
<https://groups.google.com/group/google-guice>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/5bd6aa1d-2efc-453c-ba78-707bc1e74043%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/5bd6aa1d-2efc-453c-ba78-707bc1e74043%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
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
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/a86f2bcc-26b6-499a-97b3-ba28de701295%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/a86f2bcc-26b6-499a-97b3-ba28de701295%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
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/f0fee54c-6dfc-c0d2-7e21-b44cb0a08e44%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2017-12-01 22:31:03 UTC
Permalink
This post might be inappropriate. Click to display it.
Loading...