Question

I am working on an EJB project with OpenEJB (TomEE++) container. There is a session bean whose JNDI lookup name needs to be controlled in code.

@Stateless(mappedName="SlideService", name="SlideService")
public class SlideService {

    public Map<Category, List<SlideShow>> fetchSlideShowsBycategory() {
        // TODO Auto-generated method stub
        return null;
    }

    public SlideShow fetchSlideShow(long id) {
        // TODO Auto-generated method stub
        return null;
    }

    public List<SlideShow> fetchSlideShowsByTitle(String title) {
        // TODO Auto-generated method stub
        return null;
    }
}

My problem is that, the name to which this bean gets bound is 'global/slides/SlideService'

OpenEJB seems to be using the application name, even though I have not specifically mentioned it.

Would this compromise portability ? Is it possible some other container may not use the application name ?

Is using name and mappedName attributes the right way to control the name of a stateless bean, or are there other(better) ways ?

Was it helpful?

Solution

Your problem is resolved in the EJB 3.1 specifications, any Java EE 6 certified container will use multiple JNDI names for your beans. In your code you can control the last part of the name, here a document about Portable Global JNDI Names

Here you can find a simple guide to the 3 standard scopes of JNDI Portable JNDI names in EJB 3.1

So yes, your code will be portable across any Java EE 6 certified container

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top