问题
An example:
@Remote
public interface SomeComponentRemote{
public Something processStuff();
}
//--
@Local
public interface SomeComponentLocal extends SomeComponentRemote{
}
Is that allowed? Can i do this regularly?
回答1:
Your way is not allowed as you can not mark your interface with both @Local and @Remote annotations according to specification. And it is not a good idea from point of code reading.
Recommended solution is
public interface SomeComponent {
public Something processStuff();
}
@Local
public interface SomeComponentLocal extends SomeComponent {
}
@Remote
public interface SomeComponentRemote extends SomeComponent {
}
回答2:
This code will work since @local/@remote annotations are not inherited. Is is also possible to set a no-interface-view on the bean itself with @LocalBean while implementing the remote interface (instead of a local interface).
The more important point is that every interface should only offer what is needed for the users of this class because every method you offer will be probably used and then you have to maintain this method.
The question is what you are going to do: will both interfaces offer the same methods all the time? Or is one interface a possible subset of the other (if you extend local from remote then it suggests that perhaps not every addition to local will be offered as remote). The same for @LocalBean - are there public methods that are just accessed by the ejb-container and not conceived for other users?
The only bad thing you can do is designing an interface by laziness rather than intention. Neither excludes to write less code.
来源:https://stackoverflow.com/questions/1351431/can-i-use-inheritance-in-remote-local-interfaces-ejb3