EJB调用在组件上失败

时间:2016-08-11 16:37:54

标签: dependency-injection ejb java-ee-6

当我将UserRepository接口注入控制器时,会发生以下异常:

EJB Invocation failed on component UserRepositoryMock for method public abstract java.util.List com.test.repository.IRepository.all(): javax.ejb.EJBTransactionRolledbackException: WFLYEE0042: Failed to construct component instance

我不确定,也许继承层次可能是个问题:

IRepository由IUserRepository实现。然后我还有一个抽象类AbstractRepository,它也实现了IRepository。 UserRepositoryMock扩展了AbstractRepository并实现了IUserRepository接口。

在代码中:

@Singleton
@Alternative
public class UserRepositoryMock extends AbstractRepository<IUser> implements IUserRepository {
@EJB
private IUserFactory userFactory;
public UserRepositoryMock(){
    userFactory.generateFirstUser()
}
}

AbstractRepository

@Singleton
public abstract class AbstractRepository<T extends IBO> implements IRepository<T> {
@Override
public List<T> all(){....}
}

IUserRepository:

public interface IUserRepository extends IRepository<IUser>{
...
}

其他注射工作正常,有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我建议改变这个:

public UserRepositoryMock(){
    userFactory.generateFirstUser();
}

类似于:

@PostConstruct
public void setup() {
    userFactory.generateFirstUser();
}