Search code examples
jakarta-eeglassfishejbspring-el

Access session bean by its name without JNDI-Lookup


I want to write a custom BeanResolver for the Spring Expression Language to resolve EJBs in expressions (for example "@MyBean.property=='example-value'"). How can I retrieve a bean by its name without doing a JNDI-Lookup? Do I have to write a plugin for the application server of my choice (which would be glassfish)?


Solution

  • EE injection and JNDI lookup are the entry point to all EJBs; there is no other standard way to obtain an instance of an EJB. If you're using EJB 3.1, the bindings in java:global, java:app, and java:module are well-defined and cannot be changed by a developer.

    java:global/MyApp/MyModule/MyBean!com.example.MyIntf
    java:app/MyModule/MyBean!com.example.MyIntf
    java:module/MyBean!com.example.MyIntf
    

    This is effectively locating an EJB by name. (It does require JNDI, but it's not clear from your description why JNDI itself would be problematic, though I do understand why bindings are a problem.) If you know that the EJB only supports one interface, you can omit the !com.example.MyIntf.