Tony
Tony

Reputation: 2406

Stateless EJB implements interface injection failed

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://stackoverflow.com/a/13988450/2023524 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 {
...
}

Upvotes: 3

Views: 3977

Answers (2)

mp14
mp14

Reputation: 96

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

Upvotes: 4

Albert Bos
Albert Bos

Reputation: 2062

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 {
    . . .
}

Upvotes: 1

Related Questions