Introduction to Spring #Java Short Notes

  • Open-sourced on February, 2003
  • Layered J2EE application framework
  • Inversion of Control (IoC): A Data Access Object (DAO) depends on a DataSource.
  • Allows: code to interfaces
  • Spring has classes to support Hibernate, Struts, and other frameworks
  • According to many Java developers [ref:internet], J2EE patterns are sometimes cumbersome. Spring uses patterns but made everything simpler
  • ServiceLocator -> to lookup Hibernate sessions. Spring Alternative: configure a SessionFactory
  • Spring provides/supports good programming practices such as, coding to interfaces, reducing coupling, easy testability.
  • But EJBs require to run EJB containers (WebLogic, JBoss, Websphere) to test them [testability problems inherent in EJBs] [as of 2005]
  • Over the time EJB [EJB 3.0 ] has recovered some of the issues like testability, portability [ 1. EJB 2.0 has deployment descriptors but EJB 3.0 has no deployment descriptor, 2. In EJB 2.0 you have to write Home and Remote Interfaces But in EJB3.0 you do not need to write Home interfaces, 3. In EJB 3.0, all entities are identified with '@', 4. In EJB 3.0 methods like ejbPassivate, ejbActivate, ejbLoad, ejbStore, etc. are not required, 5. EJB 3.0 is totally newly designed including the entity manager, 6. EJB 3.0 entity beans are just POJO, 7. No EJB container required to run, 8. EJB 3.0 supports Java Persistence API for all of its data needs, 9. No XMLDeployment Descriptors but annotations, 10. EJB 3.0 entity beans/JPA becomes local, 11. Queries are very flexible. Multiple levels of joins are enabled, 12. EJB 3.0 pluggable, security enabled ]
  • Spring Criticisms [as of 2005]: It's not an standard like EJBs, too heavyweight (though custom selection of modules/jars will help)
  • How Spring works: Spring can configure applications using JavaBeans. A class can expose it's dependency through setters, Spring can configure that dependency.
  • Inversion of Control/Dependency Injection: Wiring dependent objects together through a container
  • Spring Modules: Spring AOP (source level metadata), ORM (Hibernate, iBATIS, JDO support), Spring Web (WebApplicationContext, MultipartResolver, Web Utilities), DAO (Transaction Infrastructure, JDBC, DAO support), Context (ApplicationContext, UI Support, Validation, JNDI, EJB, Remoting support, Mail), MVC (Web Framework, Web Views, JSP, Velocity, Freemarker, PDF, Excel, XML/XSL)
  • Spring advantage over J2EE: Reducing Coupling: It's better not to tightly couple any application to a specific resource. In J2EE, for database operations typically an abstract Factory class (DAOFactory) is defined and a class is written for each specific implementation (DAOFactoryOracle). [J2EE Factory Pattern]. It creates additional issues such as managing dependencies of these factoried objects, handling Hibernate Session
  • Spring approach: bind interfaces to implementations, configure everything in an XML file, and modify the XML file as required for switching, unit tests can be written without the knowledge of the implementation [great with Hibernate and iBATIS] p30. Define the bean in the applicationContext.xml file, and use it from your code through ClassPathXmlApplicationContext, get a reference to the bean using ClassPathXmlApplicationContext.getBean. You can change the class property in the bean definition to use a different implementation
  • You can use Hibernate from Spring (ORM support). If you go through wrapping classes of Spring to provide Hibernate functionalities, you will not require to worry about (try, catch) checked exceptions that Hibernate usually throws

From: http://sitestree.com/?p=4923
Categories:Java Short Notes
Tags:
Post Data:2006-10-26 16:03:22

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Permanent link to this article: http://bangla.sitestree.com/introduction-to-spring-java-short-notes/

Leave a Reply