java – Separating service layer from web layer in a Spring application – Education Career Blog

I am currently learning Spring. So far I have created a basic application consisting of Hibernate/JPA entities, DAOs and classes that perform business logic. This I am calling the service layer.

If I now wish to use SpringMVC to add a web front end to this application, how should I separate the two?

i.e. do I need to create a separate ‘Dynamic Web’ project in Eclipse for the web layer? If so, how do I then integrate the two? I presume I could simply copy the service layer source into the web project, but this doesn’t seem like the best approach.


You don’t need a separate project, it really depends on whether you’ll be reusing your services elsewhere.

If you won’t be reusing your services, add your web layer to the same project, have your controllers call your service layer, and build a WAR from it.

If you will be reusing your services, create a new project for you web layer, build a JAR for your services, and import that JAR into your web layer. Something like Maven will help here.


Are you using Maven? If so, you should create a webapp project and add your “core project” as a dependency.

Leave a Comment