JBoss Community

Re: EJB 3.1, CDI, JSF 2 ERROR java.lang.NullPointerException

created by Phanor Coll in EJB3 - View the full discussion

it worked whe using @EJB instead of @Inject thanks, now I have another newbee question.. If the programming rule is that every stateless,stafull bean has to have at least one business interface, why doesnt this code works?

 

@ManagedBean(name="message")

public class index {

 

    @EJB

    MyBean bean;

 

    public String getMensaje(){

        return "Netbeans + JbossAS 7.1 do rock! " + bean.hola();

    }

}

 

 

@Stateless

public class MyBean implements MybeanInterface {

    public String hola(){

        return "it's true!";

    }

}

 

public interface MybeanInterface {

    String hola();

}

 

 

Instead of injecting the SLSB like before I have to use JNDI, It worked like this:

 

 

@ManagedBean(name="message")

public class index {

    

public String getMensaje(){

        InitialContext context;

        try {

            context = new InitialContext();

            m = (MybeanInterface) context.lookup("java:global/practicaejb/MyBean!practica.interfaces.MybeanInterface");

        } catch (NamingException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

        

        return "Netbeans + JbossAS 7.1 do rock! " + m.hola();

}

 

whats the difference?.. and sorry for this question, this is probably EJB 101, but like I said before, this is a newbe question..

Reply to this message by going to Community

Start a new discussion in EJB3 at Community