6 Replies Latest reply on Jun 5, 2011 3:38 PM by Gunnar Morling

    Accessing built-in beans in portable extension

    Gunnar Morling Newbie

      Hi,


      I'm trying to understand a bug I got for the Seam Validation module, SEAMVALIDATE-18. Basically the problem is, that under certain circumstances a built-in bean provided by the container seems not to be visible when trying to access it in a portable extension.


      More precisely, the bean of interest is the built-in bean for javax.validation.ValidatorFactory which is provided by the CDI runtime within a JEE container. In the extension (after bean discovery) I'm checking whether this bean exists via


      if (!beanManager.getBeans(ValidatorFactory.class).isEmpty()) { ... }


      Now I'd expect to find this bean in a JEE environment but surprisingly the returned set is empty.


      I debugged a bit into Weld and found that resolved beans are internally cached in TypeSafe(Bean)Resolver. As it seems this cache is built up before the built-in bean for ValidatorFactory is registered. Therefore when looking it up in the extension, the bean manager itself knows about the built-in bean but the resolver doesn't find it in the cache.


      I should mention that the problem does not always occur (I tested the extension successfully on AS 6). I assume this is due to whether bean lookups (and hence initial cache population) occur before or after the built-in bean for ValidatorFactory is registered.


      So is there anything I could do about this or is this a potential problem with Weld itself?


      Thanks, Gunnar