If you use Spring you can scale up in power a bit. Some of the benefits are:
- Declarative transactions.
- More testable code.
- Promotes good OO design
- Removes boilerplate code
- Great lightweight remoting support
- Good documentation and samples.
Spring MVC also has advantages over Stuts:
- No ActionForms. Bind directly to domain objects
- More testable code (validation has no dependency on Servlet API)
- Well defined interface to business layer
For example of Spring reducing the boilerplate code, it can turn:
Code:
public List findAllEmployees() {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.getSession();
try {
return session.find("from Employee order by surname, firstname");
} finally {
try {
session.close()
} catch(HibernateException he) {
throw new CustomRuntimeDAOException(he);
}
}
}
into
public List findAllEmployees() {
return getHibernateTemplate().find("from Employee order by surname, firstname");
}
Bookmarks