找不到带有'CommonService'类型接口的EJB,用于绑定BaseEntityServiceBean / commonService

时间:2017-06-09 17:17:17

标签: java-ee dependency-injection jboss annotations ejb

我有一个共同的服务界面:

@Local
public interface CommonService {

    public <T> T create(T entity) throws CreateException;
    public <T> T update(T entity) throws UpdateException;
    public <T> void delete(T entity) throws DeleteException;

    ...
}

CommonService实施:

@Stateless
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public class CommonServiceBean implements CommonService {

    @PersistenceContext(unitName="CLD_SV_JPA")
    protected EntityManager em;

    @Override
    public <T> T create(T entity) throws CreateException {
        this.em.persist(entity);
        this.em.flush();
        this.em.refresh(entity);
        return entity;
    }

    @Override
    public <T> T update(T entity) throws UpdateException {
        entity = this.em.merge(entity);
        return entity;
    }

    @Override
    public <T> void delete(T entity) throws DeleteException {
        Object reference = this.em.getReference(entity.getClass(), entity);
        this.em.remove(reference);
    }

    ...
}

所有实体服务都有接口(基本上只是添加泛型等的接口):

public interface EntityService<K, T extends Entity<K>> {

    public T persist(T entity) throws CreateException, UpdateException;
    public T create(T entity) throws CreateException;
    public T update(T entity) throws UpdateException;
    public void delete(T entity) throws DeleteException;

    ...
}

现在我将CommonService bean注入一个带有@EJB的抽象基类,它是所有具体服务bean的基础:

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class BaseEntityServiceBean<K, T extends Entity<K>> implements EntityService<K, T> {

    // also tried protected without getter and setter, same problem        
    @EJB
    private CommonService commonService;

    public CommonService getCommonService() {
        return this.commonService;
    }

    public void setCommonService(CommonService commonService) {
//      this.commonService = commonService;
    }

    @Override
    public T create(T entity) throws CreateException {
        return this.commonService.create(entity);
    }

    @Override
    public T update(T entity) throws UpdateException {
        return this.commonService.update(entity);
    }

    @Override
    public void delete(T entity) throws DeleteException {
        this.commonService.delete(entity);
    }

    ...
}

具体的服务bean是:

@Stateless
@Interceptors({LoggingInterceptor.class, ExceptionInterceptor.class})
public class BarwertberechnungVerwaltungBean extends BaseEntityServiceBean<Integer, Barwertberechnung> implements BarwertberechnungVerwaltung {

    @Override
    public List<Barwertberechnung> findBarwertberechnungen(Integer partnerId, List<Integer> barwertberechnungArtIds) {
        ... // load stuff
    }
}

将此部署到 JBoss AS 7 时,我得到了异常

18:52:00,136 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-11) MSC00001: Failed to start service jboss.deployment.subunit."CLD-EAR.ear"."CLD-EJB3.jar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.subunit."CLD-EAR.ear"."CLD-EJB3.jar".INSTALL: Failed to process phase INSTALL of subdeployment "CLD-EJB3.jar" of deployment "CLD-EAR.ear"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [rt.jar:1.6.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [rt.jar:1.6.0_45]
    at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_45]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011058: Failed to install component BarwertberechnungVerwaltungBean
    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:100)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    ... 5 more
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS014544: No EJB found with interface of type 'de.bla.cld.service.CommonService' for binding de.bla.cld.service.BaseEntityServiceBean/commonService
    at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:88)
    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.processBindings(ComponentInstallProcessor.java:245)
    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.access$000(ComponentInstallProcessor.java:74)
    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor$1.handle(ComponentInstallProcessor.java:199)
    at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deployComponent(ComponentInstallProcessor.java:195)
    at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:93)
    ... 6 more

显然容器找不到要注入抽象基类BaseEntityServiceBean的公共服务:

Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS014544: No EJB found with interface of type 'de.bla.cld.service.CommonService' for binding de.bla.cld.service.BaseEntityServiceBean/commonService

我的注释出了什么问题?我什么也没看到......我该如何解决这个问题?

0 个答案:

没有答案