1

OpenLiberty offers the wonderful feature of shared libraries that can be deployed in the server once and then (very skinny and fast-redeploying) WARs can access them at run-time. On the other hand, CDI provides a mechanism to reduce the bean scanning, for example:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee">
    <scan>
        <exclude name="com.mycompany.nonecdi.**"/>    
    </scan>
</beans>

My questions are - how do the two interact:

  1. Is Openliberty CDI scanner going to inspect the shared libs for beans upon WAR deployment, in the complete absence of CDI scanner restricition?
  2. Can the CDI scanner reference packages from the shared libs?
Hristo Stoyanov
  • 1,508
  • 3
  • 15
  • 24
  • I am not familiar with Liberty, but can share CDI point of view on this. 1) if you deploy your WAR, you also have beans.xml there, so you have the restrictions when you start scanning. That being said, 2) should be able to reference it as when it is checked, shared lib should already be on classpath hence FQCN should be resolvable. – Siliarus Jan 03 '18 at 08:20
  • Thanks, I am thinking the same, just wanted someone from OpenLiberty to confirm it. – Hristo Stoyanov Jan 03 '18 at 18:49

1 Answers1

1

Shared libraries are supported in Open Liberty. If there are beans.xml or bean defining annotations specified (e.g. @ApplicationScoped,etc) in the shared libraries, the beans would be found by CDI runtime. Therefore, shared libs can use CDI in Open Liberty and WebSphere Liberty.

Emily Jiang
  • 151
  • 3
  • Thanks Emily, the questions is however, about my application WAR file having a bean.xml and not the shared libray having bean.xml. Will the CDI scanner scan the shared libs then according to the WAR bean.xml? – Hristo Stoyanov Jan 11 '18 at 21:58
  • 1
    The shared lib will be scanned. In your scenario, it does not have beans.xml. Its bean discovery mode will be 'annotated', which means only classes with bean defining annotations are beans. The wars' beans.xml does not apply to other archives, but only to web-inf\classes files. – Emily Jiang Jan 12 '18 at 10:04
  • I just found this answer: https://stackoverflow.com/questions/15199929/using-cdi-in-a-websphere-shared-library?rq=1 – Hristo Stoyanov Jan 12 '18 at 17:47
  • That statement was for cdi 1.0. Shared libs were supported for cdi 1.2 and cdi 2.0. – Emily Jiang Jan 12 '18 at 22:43