简体   繁体   中英

Session bean injection with CDI

I am trying to inject a session bean into another session bean (in this particular case its the same session bean), and I get this error:

org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308 Unable to resolve any beans for Types: [interface com.windriver.dsm.labmanagement.ejb.stub.GeneralSession]; Bindings: [@javax.enterprise.inject.New(value=com.windriver.dsm.labmanagement.ejb.stub.GeneralSession.class)]

This is how I am trying to do it:

@Stateless
@TransactionManagement(value=TransactionManagementType.CONTAINER)
@TransactionAttribute(value=TransactionAttributeType.REQUIRED)
@Local(GeneralSessionLocal.class)
@Remote(GeneralSession.class)
public class GeneralSessionBean extends CRUDSessionBase
{
    @Inject @New
    Instance<GeneralSession> generalSessionInstance;

    // ...
}

I get this error when I call generalSessionInstance.get(); . Can anyone help?

Try specifying that the bean class (GeneralSessionBean) implements the GeneralSession.

In your case:

@Stateless
@TransactionManagement(value=TransactionManagementType.CONTAINER)
@TransactionAttribute(value=TransactionAttributeType.REQUIRED)
@Local(GeneralSessionLocal.class)
@Remote(GeneralSession.class)
public class GeneralSessionBean extends CRUDSessionBase implements GeneralSession
{
    @Inject @New
    Instance<GeneralSession> generalSessionInstance;

    // ...
}

A remote interface is not a bean type, which is valid for injection, according to the WebBeans spec. So you have to take the local interface (in that case GeneralSessionLocal) for the field type (and you should also implement this interface, because otherwise it also isn't a bean type of your EJB).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM