cannot find my bean using the InitialContext.lookup() method

后端 未结 2 1208
轮回少年
轮回少年 2021-01-15 21:47

I have tried to use struts 1.3 API to make a small application with EJB 3.0. Unfortunatelly i cannot use the @EJB annotation to call my bean object from inside my action cla

2条回答
  •  隐瞒了意图╮
    2021-01-15 22:34

    @EJB won't work in a standard pojo it can only be done in a managed object (i.e. another session bean)

    So...

    Here's your bean

    @Stateless(mappedName="beanName")
    public class beanName implements beanNameRemote {
    

    Here's your lookup

    Context context = new InitialContext();  //default lookup pulls from jndi properties file
    context.lookup("beanName");
    

    You can do some further reading on the mappedName to see if you want to use it or not.

提交回复
热议问题