Spring Flashcards
What is IOC?
A key characteristic of IOC is the calling code has the ability to customize the calling methods according to an external configuration (XML) file. The most common implementation of IOC is dependency injection.
What is dependency injection?
A software design pattern that promotes the single responsibility principle, which is simply saying that one module of a project only does one thing, and it does it well.
It uses a Builder pattern to obtain valid instances of your object’s dependencies and pass them to your object during the object’s creation and/or initialization. Using polymorphism and interfaces, the class that needs the dependency does not need to reference the concrete class type. Instead, you declaratively express dependencies through a configuration medium (like XML). The main goal is to decouple classes and test concrete classes in isolation.
What is decoupling?
Decoupling is also known as loose coupling, or loosen the relationship between two classes.
What is isolation testing?
Isolation testing is the process of breaking down the system into various modules so that defects can be spotted easily in isolation.
What are the different types of dependency injection and which does Spring support?
● Constructor Injection (Pico container, Spring etc):
● Setter Injection (eSpring):
● Interface Injection (Avalon): Note: Spring supports only Constructor and Setter Injection
What is Constructor Injection in Spring?
Dependencies are provided as constructor parameters.
We can inject the dependency by constructor. The tag constructor-arg subelement of tag bean is used for constructor injection.
What is Setter Injection in Spring?
Dependencies are assigned through JavaBeans properties (ex: setter methods).
What is Interface Injection in Spring?
Injection is done through an interface.
What are the benefits of IOC?
● Minimizes the amount of code in your application.
● Make your application more testable
● Loose coupling is promoted
● IOC containers support eager instantiation and lazy loading of services.
How does IOC minimize code?
With IOC containers you do not care about how services are created and how you get references to the ones you need. You can also easily add additional services by adding a new constructor or a setter method with little or no extra configuration.
How does IOC make application testable?
By not requiring any singletons or JNDI lookup mechanisms in your unit test cases. IOC containers make unit testing and switching implementations very easy by manually allowing you to inject your own objects into the object under test.
How does IOC promote loose coupling?
With minimal effort and least intrusive mechanism. The factory design pattern is more intrusive because components or services need to be requested explicitly whereas in IOC the dependency is injected into requesting piece of code. Also some containers promote the design to interfaces not to implementations design concept by encouraging managed objects to implement a well-defined service interface of your own.
How does IOC support eager instantiation and lazy loading of services?
Containers also provide support for instantiation of managed objects, cyclical dependencies, life cycles management, and dependency resolution between managed objects etc.
What is Spring?
Spring is an open source framework created to address the complexity of enterprise application development. One of the chief advantages of the Spring framework is its layered architecture, which allows you to be selective about which of its components you use while also providing a cohesive framework for J2EE application development.
What are some features of Spring?
● Lightweight: ● Inversion of control (IOC): ● AsWhat are some features of Spring?pect oriented (AOP): ● Container: ● MVC Framework: ● Transaction Management: ● JDBC Exception Handling:
What makes Spring lightweight?
Spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible.
What is Spring Inversion Control?
Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects.
What is Spring Aspect oriented Programming(AOP)?
Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.
What is Spring Container?
Spring contains and manages the life cycle and configuration of application objects.
What is Spring MVC Framework?
Model View Controller
Spring comes with MVC web application framework, built on core Spring functionality. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. But other frameworks can be easily used instead of Spring MVC Framework.
What is Spring Transaction Management?
Spring framework provides a generic abstraction layer for transaction management. This allowing the developer to add the pluggable transaction managers, and making it easy to demarcate transactions without dealing with low-level issues. Spring’s transaction support is not tied to J2EE environments and it can be also used in container less environments.
What is Spring JDBC Exception Handling?
The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS
Name the modules of Spring.
The basic Spring Framework contains the following libraries grouped by functionality.
- Core Container
- Test
- AOP
- Instrumentation
- Web and Remoting
- Data Access and Integration
What is Bean Factory?
A BeanFactory is like a factory class that contains a collection of beans. The BeanFactory holds Bean Definitions of multiple beans within itself and then instantiates the bean whenever asked for by clients.