Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdi-dev] Guice to CDI migration

I am not familiar with Narayana enough to tell you the exact problem.
But I'd try debugging through some of its bits, namely https://github.com/jbosstm/narayana/blob/master/ArjunaJTA/cdi/classes/com/arjuna/ats/jta/cdi/JTASupplier.java#L77
which is used in NarayanaTransactionManager to create the bean. It uses JNDI and then a fallback. I suppose there is no JNDI in your case, so a fallback is what should happen.
Instead you seem to be getting an exception from the JNDI resolution which is weird...

Regards
Matej

----- Original Message -----
> From: "Amit MENDAPARA - Axelor" <amit@xxxxxxxxxx>
> To: "cdi developer discussions" <cdi-dev@xxxxxxxxxxx>
> Sent: Friday, March 27, 2020 6:50:01 PM
> Subject: Re: [cdi-dev] Guice to CDI migration
> 
> 
> 
> On Fri, Mar 27, 2020 at 9:04 PM Matej Novotny < manovotn@xxxxxxxxxx > wrote:
> 
> 
> 
> 
> ----- Original Message -----
> > From: "Amit MENDAPARA - Axelor" < amit@xxxxxxxxxx >
> > To: "cdi developer discussions" < cdi-dev@xxxxxxxxxxx >
> > Sent: Friday, March 27, 2020 8:27:01 AM
> > Subject: Re: [cdi-dev] Guice to CDI migration
> > 
> > Hi all,
> > 
> > So finally I made some progress in my efforts to migrate from guice to cdi.
> > I
> > choose to use weld-servlet, resteasy and narayana-jta and integrated it
> > with
> > embedded tomcat. Most of the cases are resolved but one where I need to run
> > some initialization steps when application starts and it requires
> > transaction.
> > 
> > Can someone point me how this can be done? I have tried `@Observes
> > @Initialized(ApplicationScoped.class) ServletContext context` event but
> > here
> > transaction manager is still not available.
> 
> Observing @Initialized(ApplicationScoped.class) is a correct way to perform
> something once the app is started.
> What do you mean by "transaction manager is still not available"? How are you
> obtaining that and what exception are you seeing?
> 
> 
> I am getting following error:
> 
> Caused by: javax.naming.NameNotFoundException: Name [TransactionManager] is
> not bound in this Context. Unable to find [TransactionManager].
> at org.apache.naming.NamingContext.lookup(NamingContext.java:833)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:174)
> at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163)
> at javax.naming.InitialContext.lookup(InitialContext.java:417)
> at com.arjuna.ats.jta.cdi.JTASupplier.get(JTASupplier.java:100)
> at
> com.arjuna.ats.jta.cdi.NarayanaTransactionManager.getDelegate(NarayanaTransactionManager.java:246)
> 
> This is happening only with `@Observes @Initialized(ApplicationScoped.class)
> ServletContext context` event. Transactions are working fine with JAX-RS
> resources as well as with junit5 tests (using weld-junit5).
> 
> For the moment, I workaround the issue by injecting `UserTransaction`.
> 
> I have followed this narayana quickstart example:
> https://github.com/jbosstm/quickstart/tree/master/jta-and-hibernate-standalone
> as one requirement is to keep our current tomcat based deployment workflow.
> 
> Regards
> --
> Amit Mendapara
> 
> 
> 
> > 
> > For a context,
> > 
> > There is an `EntityManagerProducer` that produces `RequestScoped`
> > EntityManager.
> > There is an implementation of `TransactionServices` as per weld standalone
> > quickstart example.
> > 
> > With Guice, we did this with a special eager singleton Servlet and
> > overriding
> > it's `init` method.
> > 
> > Regards
> > --
> > Amit Mendapara
> > 
> > 
> > On Thu, Mar 12, 2020 at 12:28 AM Emily Jiang < emijiang6@xxxxxxxxxxxxxx >
> > wrote:
> > 
> > 
> > 
> > Glad it works for you Amit! You are welcome! +1 on the blog idea from Reza!
> > 
> > Thanks
> > Emily
> > 
> > On Wed, Mar 11, 2020 at 3:27 PM Amit MENDAPARA - Axelor < amit@xxxxxxxxxx >
> > wrote:
> > 
> > 
> > 
> > Hi all,
> > 
> > So finally after going through CDI docs (Weld documentation), I gave it a
> > try
> > and found that `@Specializes` is the exact replacement for Guice linked
> > binding. However, `@Alternative` with `@Priority` can do the same and we
> > can
> > have much better control. So that's a better option. Thanks Emily, Matej
> > for
> > the hints.
> > 
> > Regards
> > --
> > Amit Mendapara
> > 
> > Axelor India
> > 604, Luxuria Business Hub,
> > Near V. R. Mall, Dumas Road,
> > Surat - 395007 (India)
> > Phone: (+91) 261 297 7840
> > 
> > 
> > On Wed, Mar 11, 2020 at 8:34 PM Amit MENDAPARA - Axelor < amit@xxxxxxxxxx >
> > wrote:
> > 
> > 
> > 
> > Thanks Reza,
> > 
> > You are the motivation I am here on this mailing list to discuss this
> > migration and I think it can be a good case study for others too. I will
> > share my experience for sure. Thank you again.
> > 
> > Regards
> > --
> > Amit Mendapara
> > 
> > Axelor India
> > 604, Luxuria Business Hub,
> > Near V. R. Mall, Dumas Road,
> > Surat - 395007 (India)
> > Phone: (+91) 261 297 7840
> > 
> > 
> > On Wed, Mar 11, 2020 at 8:28 PM reza_rahman < reza_rahman@xxxxxxxxx >
> > wrote:
> > 
> > 
> > 
> > Just a small suggestion - it would be awesome if after the migration is
> > done,
> > you could consider writing a blog entry on it. I believe it would be highly
> > appreciated in the community. If you gave me a heads up, I would be
> > delighted to spread the word on it.
> > 
> > Reza Rahman
> > Jakarta EE Ambassador, Author, Blogger, Speaker
> > 
> > Please note views expressed here are my own as an individual community
> > member
> > and do not reflect the views of my employer.
> > 
> > Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone
> > 
> > 
> > -------- Original message --------
> > From: Amit MENDAPARA - Axelor < amit@xxxxxxxxxx >
> > Date: 3/11/20 1:38 AM (GMT-05:00)
> > To: cdi developer discussions < cdi-dev@xxxxxxxxxxx >
> > Subject: Re: [cdi-dev] Guice to CDI migration
> > 
> > Hi Emily,
> > 
> > 
> > 
> > 
> > 
> > 
> > I have tried using "@Alternative" but I have to use qualifiers to inject
> > this
> > alternative. Is there any way we can make the CDI container use the
> > "EnhancedGreetingServiceImpl" automatically without any qualifiers (without
> > any changes in module-a or app itself).
> > I don't think you need to use any qualifier here. You need to use
> > `@Priority`
> > to enable the alternative. The other way to completely override a bean, you
> > can use `@Specializes`. By the way, I am not 100% sure what your use case
> > is. A working example helps if you need further assistance.
> > 
> > 
> > I never used CDI before so it's new to me and I don't know many of it's
> > concepts (I know guice very well so at least DI and AOP concepts might be
> > similar). So I will try your suggestion but on twitter one user recommended
> > me to check `@Specializes` and that seems the proper solution as per it's
> > javadoc.
> > 
> > The project I am going to migrate is relatively complex and there are few
> > more cases I would like to discuss here. I will try to provide a test case
> > example that covers some of them.
> > 
> > Regards
> > --
> > Amit Mendapara
> > _______________________________________________
> > cdi-dev mailing list
> > cdi-dev@xxxxxxxxxxx
> > To unsubscribe from this list, visit
> > https://www.eclipse.org/mailman/listinfo/cdi-dev
> > _______________________________________________
> > cdi-dev mailing list
> > cdi-dev@xxxxxxxxxxx
> > To unsubscribe from this list, visit
> > https://www.eclipse.org/mailman/listinfo/cdi-dev
> > 
> > 
> > --
> > Thanks
> > Emily
> > 
> > _______________________________________________
> > cdi-dev mailing list
> > cdi-dev@xxxxxxxxxxx
> > To unsubscribe from this list, visit
> > https://www.eclipse.org/mailman/listinfo/cdi-dev
> > 
> > _______________________________________________
> > cdi-dev mailing list
> > cdi-dev@xxxxxxxxxxx
> > To unsubscribe from this list, visit
> > https://www.eclipse.org/mailman/listinfo/cdi-dev
> > 
> 
> _______________________________________________
> cdi-dev mailing list
> cdi-dev@xxxxxxxxxxx
> To unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/cdi-dev
> 
> _______________________________________________
> cdi-dev mailing list
> cdi-dev@xxxxxxxxxxx
> To unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/cdi-dev
> 



Back to the top