Architecture for Spring Web Application


I need understand what architecture use in new project. We want to use GWT & spring mvc as the base. Also we have about 100 entities in domain model, which need to persist in DB. So we are likely to use Hibernate as ORM solution.

  1. I can't understand what application server we should use? Can we get tomcat or there is best solution for enterprise application in our case? Suggest me please.

  2. How tomcat serves http requests, which need database operation through hibernate?

  3. When spring applicationContext.xml is read? During Each http request or not?

  4. Using Spring+Hibernate+JPA is fast way in case of middle load application?

I have two projects, implemented using these technologies:

  • Apache Tomcat
  • PostgreSQL
  • Hibernate
  • JPA
  • Spring
  • Spring security
  • JAX WS
  • GWT
  • MVP4g

I use Spring only for putting all technologies together.

I have two different applications and I'd like to share experience of using these technologies together in this apps. Both apps have no difficult logic on server, even in the second one all logic was put on client and server was only storing/getting data to/from db. GWT solved this nice. I think, minimum calculations on server is the best for cloud apps.

1. The first one is a monitoring system, that was built to solve these tasks:

  • Collect statistical information from main company server(from every 30secs to every 5 mins)

  • Make some simple calculations on server side

  • Store data in db

  • Show this data in graphical representation for end user (my colleges, dialers, etc)

So, the main problem was to get and show in charts big amount of data, that was stored in one table (about +1 million rows every 5 days). We had to show about from 5k to 20k points on one graph, and reload this graphs periodically to get actual info from server. We decided to use hibernate+jpa, but I think it was not the best way, cause we started to get problems from getting and sending 10k+ rows.

So, we decided to migrate from spring+hibernate+jpa to spring+jdbc as it works faster than the first one and uses less memory in my case. So it is better not to use hibernate if you:

  • have few entites (in my case 6)
  • have big amount of data
  • need fast load

Always remember that you need to get as less data from db as you can, using different filters etc( It didn't work in my case, cause I had to show as much info as I could to have best statistics for operator, but you also can use mathematics to average some values, numbers, etc)

As for client side, the Google Charts works pretty good with GWT. As app was placed in local network we had no problems with loading big amounts of data on clientside. I'v deployed app in clouds (Jelastic), just for test, and faced slow client loading, because of big amount of data transferings in small periods of time.

2. The second app is a cloud application for managing sales, orders, contacts, etc:

It was built to solve these tasks:

  • fast storing, getting, calculating data
  • provide user simple and pleasant interface to operate tasks, mentioned above

This app had no logic on server side. Server was only getting and storing data from db. We have devided app into few modules with help of maven (entities+daos, spring services and web GWT).

So hibernate+jpa was acting good here as we had big ammount of entities and not big tables. Plus, all clientside grids had default filters that loaded less than 100 rows, also user had to filter his search. So in case of hibernate+jpa usage in this project I have opposite directions:

  • small amount of data transferings
  • big amount of entities

As for GWT, It was great to write client side logic on pure Java, debugging code and testing newly created logic by refreshing page. I also should advise you to use MVP4g as model view presenter framework to build GWT app the right way :) It really simplifies the development process and code unerstanding.

As for tomcat we had no big problems with it in both projects.

I think these basic advises will help you to build good project! Good luck!