Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the role of Spring in Struts + Spring + Hibernate?

What role is Spring taking in Struts + Spring + Hibernate?

like image 262
JSON Avatar asked Oct 02 '08 13:10

JSON


2 Answers

Spring provides many different "modules" and different programmers will use different parts of Spring.

However, commonly in this sort of stack, you will see Spring being used as a provider of

  • An inversion of control container for dependency injection
  • An abstraction to Hibernate called "HibernateTemplate"
  • Framework classes for simplifying Aspect Oriented Programming
  • Transaction support, often "declaratively" via the IoC container and AOP.
like image 126
Cheekysoft Avatar answered Nov 07 '22 20:11

Cheekysoft


Well, Hibernate handles the persistence part, JSP handles your GUI, Struts controls the flow between pages/actions/etc, and Spring can manage all your beans which contain the main business logic, instead of using EJB. Plus it can simplify the coding of your Hibernate DAO's and transaction managing. Instead of having to code your Locator to obtain some EJB through JNDI and all that stuff, you can just get the Spring ApplicationContext and ask for the bean you need. All the beans defined in Spring can be interconnected. If you have to connect one of your beans to an external EJB through JNDI you can even do so without any code (Spring offers a JNDI proxy object which obtains the reference you give it and returns it as an object with the interface you specify). This can help you simplify unit testing of all those beans and change the config without recoding anything; you can use one of Spring's PlatformTransactionManagers to manage a DataSource or point it to a J2EE container's JTA manager; define your own pooled DataSource or use your container's DataSource published through JNDI, etc.

like image 35
Chochos Avatar answered Nov 07 '22 21:11

Chochos