user1960555
user1960555

Reputation: 161

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?

Upvotes: 1

Views: 1858

Answers (2)

dunni
dunni

Reputation: 44535

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).

Upvotes: 0

Kurt Du Bois
Kurt Du Bois

Reputation: 7665

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;

    // ...
}

Upvotes: 0

Related Questions