9 Replies Latest reply on Jul 22, 2016 6:14 AM by gytis

    Failure to get bean with BeanManager when using EAR archive

    gytis

      Hello,

       

      we have been informed recently by one of our users on Narayana forum about an issue with our Compensations framework when the application using it is deployed as an EAR archive. When transactions is being completed/cancelled compensations framework instantiates completion/compensation handler implemented by the user by using BeanManager. For some reason this works fine if the handler is deployed in a JAR or a WAR. However, if the handler comes in a JAR which is in EAR, BeanManager doesn't find the bean. The error as this is thrown by compensations framework when CDI.current().getBeanManager().getBeans(clazz).iterator() returns an empty iterator: https://gist.github.com/gytis/a9773589e383d0f63ed8aa726dc7b93c.

      I've put together a reproducer for this issue: quickstart/compensating-transactions/compensations-in-ear at bm-issue-with-ear · gytis/quickstart · GitHub. It has two tests in compensations-test module. One which invokes @Compensatable service (quickstart/HotelServiceImpl.java at bm-issue-with-ear · gytis/quickstart · GitHub) when it's deployed as a simple JAR (quickstart/HotelServiceEjbTest.java at bm-issue-with-ear · gytis/quickstart · GitHub). And another which invokes the same service when the same JAR is wrapped in EAR (quickstart/HotelServiceEarTest.java at bm-issue-with-ear · gytis/quickstart · GitHub).

      Unsuccessful bean instantiation is initiated from the interceptor of @Compensatable with which the web service is annotated. You can see the stack trace in the error above, but it eventually ends up here: narayana/BeanManagerUtil.java at master · jbosstm/narayana · GitHub.