How to use @EJB in this local context with JBoss 6

2019-08-26 18:30发布

问题:

I actually have problem with the annotation @EJB both with local and remote use. But in this question I would like to focus on the local use.

In this experiment I use Jboss EAP 6.4.

In the image below I try to show my EAR-structure and where the problem occurs, the red arrow.

My code in LocalCallSessionBean that should be injected looks like:

@EJB(mappedName="StatelessBean")
private static BeanLocal beanLocal;


public static String returnAString(String parameter)
{

    try
    {
        String string_2 = beanLocal.returnAString("LocalCallsBean-no-interface");

My problem is that beanLocal never get injected and I get a NullPointer at the last row above.

According to: https://docs.oracle.com/javaee/6/tutorial/doc/gipjf.html#girfl ...under section "Accessing Local Enterprise Beans That Implement Business Interfaces" I think this should work.

Do you guys see something that I have missed? Best regards Fredrik

回答1:

I have done some progress. I found three mistakes that I did.

1) I had dependencies that might have been in conflict with my target environment. Compare image below with previous one.

2) I used mappedName but I never got that to work, see image below what I did instead, for loacl I just needed @EJB.

3) I marked my ejb-member/ejb-field as static, I can not explain why but that just did just not work.

Hope this help some one.

Best regards Fredrik



标签: jboss-eap-6