@Remote(interface.class) 的使用
Use of @Remote(interface.class)
在 ejb 中使用 @Remote(interface.class) 有什么影响吗?
也就是说。这有什么区别:
@Remote(MyRemoteInterface.class)
@Stateless
public class MyBean implements MyRemoteInterface {
还有这个:
@Stateless
public class MyBean implements MyRemoteInterface {
当界面看起来像这样时:
@Remote
public interface MyRemoteInterface {
当通过远程接口使用 bean 时,这两种解决方案在 JBoss 6.4 上都能正常工作。
没有区别,只是写法不同,参见 EJB 3.1 规范的 2.1.2:
The interface can be annotated on with @Local or @Remote on the
interface class, or annotated with @Local (.class) or @Remote
(.class) on the bean class
除了@maress在他的评论中所说的,在bean class上使用@Local
和@Remote
还有其他优点/缺点,你可以找到一个很好的总结here.
我把你问题的相关部分引用一下:
Bean class 带有@Local / @Remote 注释:
Advantages:
- Information about interface type is loosely-coupled. You can ship your API to the client and don’t care about EJB semantics. If you’ll hide it with a facade your end-user (even a developer) doesn’t even have to know it’s using EJB technology under the hood.
- Thanks to the Java implements clause you can use javac or your IDE to make sure all EJB business methods are implemented.
Disadvantages:
- Your EJB must now define all its business interfaces using
@Local
annotation so it’s additional work for you. Not only you implement an
interface but you need to remember to declare that your EJB is
exposing it. There is nothing (from the javac perspective) preventing
you from putting an interface into @Local
annotation that is not
actually implemented by your EJB.
带有@Local/@Remote注解的接口:
Advantages:
- You don’t have to specify interface type in your EJB. You just “Java implement” it and the container do the rest.
- Information about interface type is strongly attached to the interface so it might be easier to understand for other developers.
- Thanks to the Java implements clause you can use javac or your IDE to make sure all EJB business methods are implemented.
Disadvantages:
- Your interface now is tightly coupled with EJB technology (importing
javax.ejb.*
package.) You must now provide your API client
with required libraries to use it.
在 ejb 中使用 @Remote(interface.class) 有什么影响吗?
也就是说。这有什么区别:
@Remote(MyRemoteInterface.class)
@Stateless
public class MyBean implements MyRemoteInterface {
还有这个:
@Stateless
public class MyBean implements MyRemoteInterface {
当界面看起来像这样时:
@Remote
public interface MyRemoteInterface {
当通过远程接口使用 bean 时,这两种解决方案在 JBoss 6.4 上都能正常工作。
没有区别,只是写法不同,参见 EJB 3.1 规范的 2.1.2:
The interface can be annotated on with @Local or @Remote on the interface class, or annotated with @Local (.class) or @Remote (.class) on the bean class
除了@maress在他的评论中所说的,在bean class上使用@Local
和@Remote
还有其他优点/缺点,你可以找到一个很好的总结here.
我把你问题的相关部分引用一下:
Bean class 带有@Local / @Remote 注释:
Advantages:
- Information about interface type is loosely-coupled. You can ship your API to the client and don’t care about EJB semantics. If you’ll hide it with a facade your end-user (even a developer) doesn’t even have to know it’s using EJB technology under the hood.
- Thanks to the Java implements clause you can use javac or your IDE to make sure all EJB business methods are implemented.
Disadvantages:
- Your EJB must now define all its business interfaces using
@Local
annotation so it’s additional work for you. Not only you implement an interface but you need to remember to declare that your EJB is exposing it. There is nothing (from the javac perspective) preventing you from putting an interface into@Local
annotation that is not actually implemented by your EJB.
带有@Local/@Remote注解的接口:
Advantages:
- You don’t have to specify interface type in your EJB. You just “Java implement” it and the container do the rest.
- Information about interface type is strongly attached to the interface so it might be easier to understand for other developers.
- Thanks to the Java implements clause you can use javac or your IDE to make sure all EJB business methods are implemented.
Disadvantages:
- Your interface now is tightly coupled with EJB technology (importing
javax.ejb.*
package.) You must now provide your API client with required libraries to use it.