Modular web applications
I'm working on a web application (Spring, Hibernate, Apache Tomcat) with more interfaces (HTML, mobile HTML, XML, REST). So I decided to split application to more web apps to avoid mixing files from the interfaces. I have extracted core classes of the application (business logic, Hibernate DAOs) to external jar and included it to web applications. Everything seemed to be perfect.
But now I have realized there are more instances of the core on the server, more EntityManagerFactories, Spring contexts,...). When I will try to communicate over Spring beans (e.g. add scheduler task in one interface, remove it in another) or use Hibe开发者_JS百科rnate second-level cache, it should break down.
What is the best solution?
If you have more webapps, you will have more Spring appcontexts as well. That is a possible workaround that splix suggested, but perhaps it's too much for your scenario (I would only do that if the application was really big)
I don't really know what you mean by XML interface. XML-RPC? Webservice? For the
- mobile UI I would use Spring Mobile (many resources there),
- REST Spring MVC, see tutorial here,
- for HTML Spring MVC again,
- if XML means XLM-RPC, see sample here.
- for webservices: Spring Web Services.
Have all your logic in a service layer, doesn't really matter if it's in an external jar or not if you aren't going to re-use it in the future, and have one Spring appcontext with many views.
I know few projects with same requirements. We had used 2 standalone servers: API server and Web server. API server have access to all data, and can execute some set of queries against it. Result object are serialized to XML, JSON or Protobuf. It's very easy to make using Spring + custom View Resolver or Jersey (i have two project - one based on spring, second on Jersey, an I suggest you to use spring)
Web server calls this API (using protobuf, for example), and prepare html answer to user browser, based on results (and there also can be some ajax calls to this API server).
Mobile app can access this API server without any problem too.
精彩评论