Enabling CDI in ADF Applications targeting WLS 12C

If you had tried using  Contexts and Dependency Injection (CDI) in your ADF app targeting WLS 12C, you might have already noticed the issue that I'm mentioning here - CDI things are not working in the application by default. Well, here is a solution. See this blog which talks about the same: post https://weblogs.java.net/blog/mriem/archive/2013/12/10/jsf-tip-54-enable-cdi-when-bundling-jsf?force=659

To keep things simple, do the  following:

  1. Download the cdi-enabler jar from the following mavne repo:  https://maven.java.net/content/groups/public/com/oracle/cdi-enabler/cdi-enabler-1_0/1/cdi-enabler-1_0-1.jar
  2. Add it as dependency to your view controller project where you use CDI.
  3. Open the beans.xml file and add alternatives as shown below:


<?xml version = '1.0' encoding = 'windows-1252'?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"
       xmlns="http://java.sun.com/xml/ns/javaee">
    <alternatives>
        <class>com.oracle.cdi_enabler.CdiConversation</class>
    </alternatives>
</beans>

Now try running the app, I can see CDI works for me. I hope you may also see the same ;)

Update : 
The thing mentioned here is a  work around for class loading issue that may arise when an application using CDI, packaged with its own JSF implementation(Not the one provided by the underlying container). As both the CDI and JSF implementation are not loaded by class loaders of same level, CDI cannot simply work with JSF implementation provided by app. This is the case for an ADF Faces app. Work around is to make use of CDI 'alternatives'  feature to plugin  pieces that needs to work with the JSF classes loaded in the current application's context. 

Comments