Spring Framework Interview Notes : Part One Core
These is part of a set of posts which might help in getting up and running with Spring framework. I will try to be lucid and do away with all the complex junk the authors throw at you to make you buy their books.
Apparently, Spring framework was the answer to the questions posed by complex world of Java enterprise programming brought to you by frameworks like struts and EJB. It was meant to make it easy to code large projects and thus take away the frustration of the beloved Java programmer.
Now i am not sure how much you enjoyed copying and pasting the context files and hand-rolling those smoking hot beans but after some time you i found it similar to EJB 1.2 and Struts roll in one.
A Spring component was the good old POJO without sprinkled with any Spring framework classes, like Struts. Although now they have changed that by using the great new feature called Java Annotation, @Bean. We will not make your POJO depend on us has been changed to use us now and you cannot run away from us.
So now with Spring 3.0 and 4 you need to remember a whole lot of classes and annotations, which is dramatically going the way of remember the EJB home ,away and other interfaces.So I think the only benefits you really get using Spring is it actually removes a lot of boilerplate code (JDBC example) and Dependency Injection using interfaces which actually gives you a lot of place to move around.
Dependency Injection or the magic that Spring does to get your dependency pushed in your code is simple to understand, a software called spring reads a context file (@Configuration for annotation junkies) created these object and puts in your code. A couple of ways these is accomplished are know as Setter injection or Constructor injection or Autowired dependencies.
The context file can be picked up from classpath, filesystem or @Configuration annotated java files (some more ways are there check out the docs).
org.springframework.beans.factory.BeanFactory and org.springframework.context.ApplicationContext are 2 Spring containers who the masters which play with these @Beans, They control the lifecycle of the bean from instantiation to destruction and beyond.
Bean Lifecycle
Spring framework comes with a lot of modules including but now limited to modules to work with Core, JDBC, JMS, Web, WebMVC ,AOP and test etc. The core is the heart of these modules which contains the beanfactory and application context,this module also provides many enterprise services such as email, JNDI access, EJB integration, and scheduling.
Nice features like custom profiles using @Profile, Caching support, property injection, support for Servlet 3.0, JPA support in Java config files, and support for @RequestMappingproduces and consumes attributes and other Web and REST specific support was introducted in Spring 3+.
Spring 4 provided features for Java 8 and Websocket support.
Although a lot of these features provide easy ways to put great features in your code, always remember minimal interference in your code the mush touted Spring feature is diluting more and more, your code is now more and more depended on Spring.
Comments
Post a Comment