views:

54

answers:

2

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.

+2  A: 

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

Brian Clozel
+2  A: 

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.

GaryF
Thanks. If were to take the latter approach, would the JAR simply contain the service layer classes, then they would get wired together by a Spring xml file residing in the web project?
William
Yeah, the JAR would just have the services. You could then wire them in with your Spring config.
GaryF
Makes sense, thanks :)
William