Stateless EJB implements interface injection failed

本秂侑毒 提交于 2019-12-09 03:26:26

问题


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

回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/34352909/stateless-ejb-implements-interface-injection-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!