Hello. For various reasons both good and bad, our codebase has lots of
EJBs in it that are defined like this:
@Local
@Stateless(name = "Caturgiator")
public class CaturgiatorBean implements Caturgiator {
}
As it turns out, Caturgiator extends a superinterface:
public interface Frobnicator {
}
public interface Caturgiator extends Frobnicator {
}
In my SLSB above as I have it written, I certainly would not expect it to
have any other business interface other than Caturgiator, and indeed it
does not.
If though I wanted to ensure that it *also* exposed the
Frobnicatorbusiness interface, I thought I had two options. One
option is obvious,
and I'll mention it here just for completeness:
@Local({ Caturgiator.class, Frobnicator.class }) // specify explicitly
@Stateless(name = "Caturgiator")
public class CaturgiatorBean implements Caturgiator {
}
...and works just fine.
But we have many, many, many (many!) EJBs that follow this pattern. Bulk
changing all of their @Local annotations to explicitly specify all business
interfaces is going to be tedious to say the least. I was hoping that I
could do something else.
Section 4.9.7 of the EJB 3.1 specification says (in part, on page 125):
"A bean class is permitted to have more than one interface. If a bean class
has more than one interface—excluding the interfaces listed below—any
business interface of the bean class must be explicitly designated as a
business interface of the bean by means of the Local or Remote annotation
on the bean class *or interface* or in the deployment descriptor."
I was hoping that the part that reads "by means of the Local or
Remoteannotation on the bean class *or
interface*..." would help me out here. So I amended my example as follows
(note the addition per spec of @Local to Frobnicator):
@Local // hope this will "flow downhill" into the
// business interfaces exposed by
// CaturgiatorBean....
public interface Frobnicator {
}
public interface Caturgiator extends Frobnicator {
}
@Local // probably leaving this here is problematic
@Stateless(name = "Caturgiator")
public class CaturgiatorBean implements Caturgiator {
}
That didn't work; the only business interface exposed by Glassfish 3.1.2.2
(the reference implementation) was Caturgiator.
Removing the potentially problematic @Local annotation from
CaturgiatorBeandid nothing; the only exposed business interface was
(again)
Caturgiator. This surprised me.
Is this a bug in Glassfish, or have I misunderstood this part of section
4.9.7 that says I can put @Local on the business interfaces I want to
expose and therefore have any EJBs that indirectly implement them have them
show up in their list of business interfaces?
Thanks,
Best,
Laird
--
http://about.me/lairdnelson