当前位置: 动力学知识库 > 问答 > 编程问答 >

glassfish - Java EE inter-application communication

问题描述:

We are developing several separate applications/modules, that we deploy onto Glassfish 3.1.1 application server. There are cases where these applications need to call each others methods, through a remote interface. What is the best practice when it comes to packaging these remote interfaces? E.g. if A needs to call B's remote interface, would you extract B's remote interface in a separate JAR file and package it together with module A? What if this remote interface references an entity class. Would you package this entity class together with the interface in this JAR file?

If you have any feedback on this topic, feel free to suggest how you think this should be done.

网友答案:

I spent my last job solving this exact problem.

This is what EJBs are designed to do. An EJB has both an implementation and an interface. The interface goes into a client jar that is used by your applications:

@EJB
MyService myService;

The implementation is packaged separately and installed somewhere else your server:

@Stateless
@Remote({MyService.class})
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class MyServiceBean implements MyService {
...
}

You should not have applications calling each other directly in Java EE! (But you can, in some cases) Think of EJBs as extremely lightweight, single purpose services, where you extract common business logic between your apps.

Your question sounds like a circular dependency situation where AppA calls AppB and AppB calls AppA. Extract the business logic AppA and AppB are using from AppA and put it into and EJB. Do the same for AppB. Now you have 2 apps and 2 EJBs, where common business logic can be called from either app.

Easy, right? Let me know how to explain this better!

分享给朋友:
您可能感兴趣的文章:
随机阅读: