Stateless EJB implements interface injection failed
Asked Answered
B

2

3

Wildfly 8.2.0

I have a Stateless EJB and an interface.

@Local
@Stateless
public class Bean implements IBean{
...
}

@Local
public interface IBean {
...
}

But I get a WELD Error. If Bean doesn't implement the interface there is no errors. According to https://mcmap.net/q/832472/-can-an-ejb-bean-implement-multiple-interfaces and https://blogs.oracle.com/arungupta/entry/what_s_new_in_ejb there should be no error.

Error:

WELD-001408: Unsatisfied dependencies for type Bean with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject private mypackage.anotherBean.bean

Update: I've tried all possible combinations with Local but it doesn't help. Only if interface is removed there is no error.

@Stateless
public class Bean implements IBean{
...
}

@Local
public interface IBean {
...
}

//*****************************
@Stateless
public class Bean implements IBean{
...
}

public interface IBean {
...
}
//************************************
@Local
@Stateless
public class Bean implements IBean{
...
}

public interface IBean {
...
}
Banky answered 18/12, 2015 at 10:2 Comment(0)
C
4

When you want to inject a bean whether by EJB (using @EJB) or CDI (using @Inject) container you declare a variable with interface type. Concrete implementation of declared interface is found by a container during application deployment. In your example the problem is not with annotations but with a declared type being injected (Bean instead of IBean).

Conchita answered 20/12, 2015 at 2:29 Comment(0)
G
1

You need to remove @Local from Bean.

@Stateless
public class Bean implements IBean{
...
}

Because you define 2 possible Local WELD doesn't know which one to use.

The oracle documentation show this too with @Remote interface:

@Remote
public interface Foo { . . . }

@Stateless
public class Bean implements Foo, Bar {
    . . .
}
Guelders answered 18/12, 2015 at 10:9 Comment(1)
Thank you for your answer. But it doesn't help. See question update.Banky

© 2022 - 2024 — McMap. All rights reserved.