Core Technologies Flashcards
What is the Inversion of Control (IoC) principle?
IoC is also known as dependency injection (DI). It is a process whereby objects define their dependencies instead of creating them themselves. Code is cleaner with the DI principle, and decoupling is more effective when objects are provided with their dependencies
What is the difference between the interfaces BeanFactory and ApplicationContext?
The BeanFactory interface provides an advanced configuration mechanism capable of managing any type of object. ApplicationContext is a sub-interface of BeanFactory
What is a Bean in Spring?
A bean is an object that is instantiated, assembled, and managed by a Spring IoC container. Otherwise, a bean is simply one of many objects in your application. Beans, and the dependencies among them, are reflected in the configuration metadata used by a container.
What is the flow of Spring DI Container?
It recieves POJOs and Configuration metadata and it produces a fully-configured ready-to-use system.
What is Configuration metadata?
It represents how you, as an application developer, tell the Spring container to instantiate, configure, and assemble the objects in your application. It can be supplied using XML or Annotations.
What is the role of BeanDefinition?
Each BeanDefinition object stores information about a bean. Examples of properties are class, name and scope.
How the container identifies a Bean?
The container identifies a bean using identifiers. Each bean have one or more identifiers.
What are the two DI variants and which one should I use?
Constructor-based and Setter-based Dependency Injection. The Spring team generally advocates constructor injection, as it lets you implement application components as immutable objects and ensures that required dependencies are not null. Furthermore, constructor-injected components are always returned to the client (calling) code in a fully initialized state.
What is autowiring?
It’s a mechanism whereby Spring resolve collaborators (other beans) automatically for your bean by inspecting the contents of the ApplicationContext. It has two main advantages:
Autowiring can significantly reduce the need to specify properties or constructor arguments.
Autowiring can update a configuration as your objects evolve
What ApplicationContextAware is used for?
The ApplicationContextAware interface is implemented when a bean needs to access the ApplicationContext.
Which are the two main types of Bean Scopes?
Singleton (Default). One bean for the whole container.
Prototype. Creates one bean everytime is used.
What BeanNameAware is used for?
The BeanNameAware interface is implemented when tthe a bean needs to modify its name.
What is the @Import Annotation used for?
It is mainly used for creating composed configuration, reducing bean definition complexity. It accepts an array of classes that are usually annotated with the @Configuration annotation.
What is a Spring profile?
A profile is a named, logical group of bean definitions to be registered with the container only if the given profile is active.
What is the @Profile Annotation used for?
The @Profile annotation lets you indicate that a component is eligible for registration when one or more specified profiles are active.