Search code examples
cdiopen-liberty

OpenLiberty shared libraries and CDI


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?

Solution

  • 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.