views:

47

answers:

1

I'm building a simple web application that handles a simple database using struts and hibernate (so far the application works just fine with these two frameworks), Now I want to add Spring to this application. I have some basic knowledge of how Spring works, but I don't know to which part I need to add Spring's capabilities.

Application's overall structure.

Hibernate as the persistence layer. Struts manages the overall control of the business objects (using form beans and action classes). and for the separation of these two layers I've used a class that manipulates the business logic (like DAO but not exactly).

I was thinking of adding Spring to this business logic class.

Expecting some expertise ideas...

Thanks.

A: 

First of all, Spring will help you to organize your code properly in sense of overall architecture. Spring actively promotes idea of low coupling and programming against interfaces.

When you let Spring to create instances of your services or infrastructure objects and allow it to manage dependencies among them, you keep your code remain more supportable and easier to test.

I should say, that Spring helps a lot to test all the code it manages. For example, if you do some DAO testing it takes care of transactions and dependency injections. Here you read more about how Spring helps you with testing.

Also Spring has pretty nice integation with Hibernate. For example, HibernateTemplate implements most common operation for you, so you can reuse it in DAO objects. Also it's very convenient to configure Hibernate with Spring.

Regarging Web Tier I could say that Spring has its own MVC framework. I'm not sure, if it could be integrated with Struts, but you definetely should consider approaches they used.

Here you can find more information on potential benefits of using Spring in your application.

wax