Spring Core Flashcards
What are Spring Projects and Spring Modules?
Spring Projects are built on Spring modules and provide solutions to other issues faced by enterprise applications.
The Spring Framework consists of features organized into about 20 modules such as CORE Container, Data Access, Web. These modules contain containers and frameworks.
What is IOC and what does the IOC Container do?
IoC is a design principle which recommends the inversion of different kinds of controls in object-oriented design to achieve loose coupling between application classes. Hollywood Principle: don’t call us we’ll call you
IoC Container (a.k.a. DI Container) is a framework for implementing automatic dependency injection
What is dependency injection and what are some of the benefits of using dependency injection?
Dependency Injection is a fundamental aspect of the Spring framework, through which the Spring container “injects” objects into other objects or “dependencies”. Simply put, this allows for loose coupling of components and moves the responsibility of managing components onto the container.
What types of dependency injection does Spring support?
Constructor-Based Injection
Setter Injection
Property-Based Injection
What are some differences between BeanFactory and ApplicationContext? Which one eagerly instantiates your beans?
BeanFactory loads beans on-demand, while ApplicationContext loads all beans at startup.
ApplicationContext is an interface that extends the BeanFactory interface and allows us to wire our beans and define their relationships to enforce dependency injection
ApplicationContext eagerly instantiates the beans.
What is the Spring Bean lifecycle?
the spring container gets started. After that, the container creates the instance of a bean as per the request and then dependencies are injected. And finally, the bean is destroyed when the spring container is closed.
What is bean wiring? What about autowiring?
Bean wiring is the process of combining beans with Spring container. You tell the container what beans are needed and how the container should use dependency injection to tie them together. All beans have to be initialized in an xml file.
Autowiring let Spring figure out dependencies automagically. No need to define beans in .xml
What are the different ways that Spring can wire beans?
The spring bean autowiring functionality has four modes. These are ‘no’, ‘byName’, ‘byType’ and ‘constructor’.
Through autowiring and through bean wiring in the xml
What are the scopes of Spring beans? Which is default?
singleton: default
prototype:
request:
session:
global session:
What is the concept of component scanning and how would you set it up?
This part of “telling Spring where to search” is called a Component Scan. You define the packages that have to be scanned. Once you define a Component Scan for a package, Spring would search the package and all its sub packages for components/beans.
Syntax <context:component-scan></context:component-scan>
What are the benefits and limitations of Java configuration?
advantages:
- compile time check
- refactoring
- tests flexibility
disadvantages
- not so good with smaller projects
What does the @Configuration and @Bean annotations do?
@Configuration annotation indicates that a class declares one or more @Bean methods
@Bean is a method-level annotation and a direct analog of the XML <bean></bean> element
What is @Value used for?
@Value is a Java annotation that is used at the field or method/constructor parameter level and it indicates a default value for the affected argument.
What is Spring Expression Language? What can you reference using SpEL? What is the difference between $ and # in @value expressions?
The Spring Expression Language (SpEL for short) is a powerful expression language that supports querying and manipulating an object graph at runtime.
${} can only do get and #{} can do get and set.