当前位置: 首页 > 知识库问答 >
问题:

WELLD-001408类型[LdapService]在注入点具有限定符[@named]的不满足依赖项

曹季同
2023-03-14

我的LdapService类是一个无状态EJB,默认无参数构造函数(此项目是一个EJB包)

@Stateless
public class LdapService {

@Inject
public LdapService() {

} ...

我试着把它注入到另一个类中,比如:

public class UserService {

private static final Logger logger = LoggerFactory.getLogger(UserService.class.getCanonicalName());
@Inject
private LdapService registerService;

@EJB(beanName = "Janus-session-1.0.jar#UserBean")
private TUserBean userBean;

...}

CDI可以识别带有@EJB注释的bean,但注入点向我抛出了关于@Inject的错误:

如果在LdapService中使用@named(“LdapService”),然后在注入点使用:

@Inject @Named("LdapService") private LdapService registerService;

然后我得到了这个错误:

部署失败。消息是:org.jboss.weld.exceptions.deploymentexception:WELD-001408类型[LdapService]在注入点[[field]@inject@named net.ab4cus.project.business.userservice.registerservice]未满足限定符[@named]的依赖项

我如何解决这个错误并消除歧义?或者对其他bean做@inject的正确方法是什么?

谢谢你。

编辑--------------------------------------------------------

java.lang.NullPointerException
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.<init>(CDIComponentProviderFactory.java:94)
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer.initialize(CDIComponentProviderFactoryInitializer.java:76)
at com.sun.jersey.spi.container.servlet.WebComponent.configure(WebComponent.java:572)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.configure(ServletContainer.java:314)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:604)
Truncated. see log file for complete stacktrace

如果我尝试使用前端,任何时候访问一个bean时,我都会得到这个错误(对于每个bean):

SEVERE: 
java.lang.IllegalArgumentException: Can not set net.ab4cus.project.session.TUserBean field net.ab4cus.project.business.UserService.userBean to net.ab4cus.project.session.UserBean_o7pydo_NoIntfViewImpl
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)

我正试图解决这个问题,但现在没有任何线索:/

共有1个答案

宋飞文
2023-03-14

我的第一个错误的解决方法是:

-从LdapService和默认构造函数中删除@stateless和@inject

public class LdapService {

}...

-为LdapService创建接口并@将此接口注入UserService

public class UserService {

private static final Logger logger = LoggerFactory.getLogger(UserService.class.getCanonicalName());
@Inject
private LdapServiceInterface registerService;

@EJB(beanName = "Janus-session-1.0.jar#UserBean")
private TUserBean userBean;

...}
 类似资料: