gpt4 book ai didi

java - Weld 忽略生产者

转载 作者:行者123 更新时间:2023-11-30 09:19:42 24 4
gpt4 key购买 nike

我正在尝试将 war 部署到 JBoss AS 7.1.1 服务器中,但在尝试注入(inject) EntityManager 时部署失败:

17:44:48,037 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.unit."c3e.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."c3e.war".WeldService: org.jboss.weld.exceptions.DeploymentException: Exception List with 1 exception:
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[field] @Inject xyz.beans.UploadImpl.em]
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:275)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:244)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:107)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:127)
at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:346)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:331)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)
at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83)
at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)

通常我会认为这是因为 Weld 无法找到合适的 bean 来注入(inject)。但是,我为 EntityManager 定义了一个生产者:

@ApplicationScoped
public class Resources {
@PersistenceContext(unitName="myUnit", type=PersistenceContextType.EXTENDED)
private EntityManager entityManager;

@Produces
public EntityManager getEntityManager() {
return entityManager;
}
}

它提示的注入(inject)点如下所示:

@RequestScoped
@Named("upload")
public class UploadImpl implements Upload, Serializable {
private static final long serialVersionUID = 1L;

@Inject
EntityManager em;
}

在另一个项目中,完全相同的设置工作得很好。有什么想法吗?

最佳答案

问题在上面的评论中得到了回答:@Produces 注释是从错误的包中导入的。谢谢你,Antoine Sabot-Durand!

关于java - Weld 忽略生产者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17838997/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com