Search code examples
javajakarta-eedependency-injectioncdiwebsphere-8

@Inject a bean from an EJB project gives UnsatisfiedResolutionException


I have two maven projects.

  1. One is packaging type ejb, including a beans.xml in the /META-INF
<?xml version="1.0" encoding="UTF-8"?>
<beans 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    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"
>
  1. One is packaging type war, including a beans.xml in the /WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<beans 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    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"
>
</beans>

These are then packaged into a single ear.

In my ejb project, I have a class Banana, and in the war project, I have a class Monkey.
I then try to run this in WAS 8.5, so it'll use JEE 6
However, when I try to @Inject Banana cdiBanana in the Monkey class, it fails.
It gives the message

javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.food.Banana] is not found with the qualifiers
Qualifiers: [@javax.enterprise.inject.Default()]

When I make the Banana a @Stateless EJB, and give the Monkey a @EJB Banana ejbBanana it works.

Why wouldn't this work? And what should I do or try to make it work?

Maybe related to CDI: Why are there unsatisfied dependencies in the following setup? ?


Solution

  • For now, I'll close this question. It looks like the problem is the JEE6 spec.

    • Running this in liberty (JEE7) it works fine.
    • Running in Wildfly (JEE7) works fine
    • Running in JBoss (JEE6) fails
    • Running in WAS 8.5 (JEE6) fails.

    Apparently, @Inject a bean from another Ejb-jar gives problems for the container. When you use @EJB it works fine.