0

When injecting a simple CDI managed bean into a servlet (starting from the generated code sample "SimpleServlet"), when accessing the servlet, Bluemix Liberty logs this error :

"SimpleServlet cannot be injected as class wasdev.sample.servlet.SimpleServlet is not in a bean archive."

This is so even when a beans.xml file with discovery "all" is used.The target looks like this

The target with bean.xml

Mustansir Ali
  • 305
  • 1
  • 2
  • 9

2 Answers2

2

Reason for Error :

The error is due to not having a beans.xml in the built application war i.e. JavaHelloWorldApp.war

Currently, for performance reasons, the beans.xml file is always required in order to use CDI on Bluemix.

Solution :

Copied the bean.xml inside the /src/main/webapp/WEB-INF/beans.xml then built the code.

This made sure that the bean.xml is packaged into the war file i.e. JavaHelloWorldApp.war and the error is resolved.

Mustansir Ali
  • 305
  • 1
  • 2
  • 9
0

To verify bean.xml is deployed correctly to Bluemix, select the java application on Bluemix console, click and open the java application dashboard. Select Runtime, select Files tab, browse and verify that the bean.xml is deployed correctly inside WEB-INF as shown in the snapshot below.

Bean.xml deployed in Liberty Bluemix

Mustansir Ali
  • 305
  • 1
  • 2
  • 9