Search code examples
javaspringmavenspring-mvcprojects-and-solutions

Organizing Spring Web Project


I need to create a Spring Maven Rest Project. I tried googling and found that a Spring MVC project can be organized in the following way-

  • controllers
  • dao
  • service
  • model
  • exception

My doubt here is that I dont need to fetch anything from database rather I will invoke third party rest services to fetch data based on user's requests. I just need to take request from user and invoke a third party service to fetch data for the user's request and save it in a dynamically decided database and table.

So do I need DAO or repository package at all? If not then in which package should I keep my logic of fetching data from rest services. Also, in which package should I keep my rabbit mq listeners and senders? I dont have any views for my applications, do I still need to follow MVC pattern. What project structure / pattern I can follow here. I am very confused. Are there any good books that explains all such questions?


Solution

  • What is a DAO? They are your Data Access Objects. They are services which abstract your persistance strategy. This can be done through database queries, but similarly it could behandled through webservices.
    So, personally, I would be fine with the DAO holding communication to your persistance layer... which just happens to be webservices.

    It is quite possible you do not have any views. It sounds like you're creating a webservice yourself. In that case, it is fine not to have any views (although you could use views if, for example, you're returning xml and decide to use view-templates to render the output. Not something I'd recommend, but...)

    In my opinion: Your DAO's ensure the persistance and fetching of your Model objects. Your services work plainly on your model objects, and possibly do other stuff not handled by your DAO's. Like aggregateAndColorAllBananas(Set<Banana> bananas) is something your service would do. Or countAllBananasInAllSources() (which uses the ChiquitaDAO to get all chiquitabananas and the MuditaDAO to get all Mudita bananas)