I'm using the following Bean class:
@Stateless(name="UserBean", mappedName="UserBean")
@LocalBean
public class User implements UserRemote {
@PersistenceContext
private EntityManager em;
public User() {
}
public String login(String username, String password) {
Query query = em.createQuery("...");
return "xyz";
}
}
And my method is
public String myMethod() {
try {
User user = (User) new InitialContext().lookup("UserBean");
return "xyz";
} catch (NamingException e) {
e.printStackTrace();
}
return null;
}
Here I'm getting a
javax.naming.NameNotFoundException: Unable to resolve 'UserBean'. Resolved ''; remaining name 'UserBean'
The JNDI lookup name 'UserBean' seems to be correct. No idea what the problem is. Can anyone please help? I've deployed my application on weblogic 12c, using JPA 2.0 and EJB 3.x
Thanks in advance.
The problem was I was using a Remote Interface. Using simply the @stateless annotation without mapped name The following code worked:
new InitialContext().lookup("java:global/ProjectName/ModuleName/BeanName!FullyQualifiedNameOfRemoteInterface");
Thanks @Andre!