我正在我们公司做项目,我在注入对象时遇到问题。让我们考虑一下我有这个实体提供者:
@Stateless
@TransactionManagement
public class EntityProviderBean<T> extends CachingMutableLocalEntityProvider<T> {
public EntityProviderBean(Class<T> entityClass) {
super(entityClass);
setTransactionsHandledByProvider(false);
}
@PersistenceContext(unitName = CoreApplication.PERSISTENCE_UNIT)
private EntityManager em;
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
protected void runInTransaction(Runnable operation) {
super.runInTransaction(operation);
}
@PostConstruct
public void init() {
setEntityManager(em);
setEntitiesDetached(false);
}
}
并使用上面的实体提供者扩展了 JPAContainer
@UIScoped
public class IncidentContainer extends JPAContainer<Incident> {
private static final long serialVersionUID = 8360570718602579751L;
@Inject
EntityProviderBean<Incident> provider;
public IncidentContainer() {
super(Incident.class);
}
@PostConstruct
protected void init() {
setEntityProvider(provider);
}
}
问题是(我理解)我无法使用类类型定义 @Inject 对象,因为注入方法需要空白构造函数。这里有某种解决方案如何使它起作用吗?现在我得到了例外
org.apache.webbeans.util.InjectionExceptionUtils.throwUnsatisfiedResolutionException(InjectionExceptionUtils.java:77)
非常感谢您的回答:) Ondrej