Posts

Showing posts from May, 2019

Spring Beans

1. What are Spring Beans? Spring Bean is an object that is managed by the Spring Framework. A Spring Bean is instantiated, configured, and managed by the Spring Framework container (IoC container). You can define the beans in a configuration file or use annotations. The beans are then instantiated by the Spring IoC container, added to the Spring ApplicationContext, and injected into your application at the points they are asked for. 2. What are the different Bean scopes? Beans, which are Spring-managed Java classes are created and wired by the Spring Framework. Spring allows you to define how these beans will be created. The scope of the bean is one of those definitions. To specify the bean scope, you can either use Spring annotations or define it in the configuration file. Spring Framework supports the following scopes: Singleton: If you use this bean scope, no matter how many times you call the getBean() method, the same bean instance will be returned. This is the de

Dependencies in Spring

1. What is Dependency Injection (DI) in Spring? Inversion of Control (IoC) in Spring is implemented through Dependency Injection. DI says that you just need to describe how the objects should be created rather than creating your objects yourself. When you use DI, you don’t have to directly connect your components and services in the code but you just need to describe which services are required by which components. The IoC container is then responsible for connecting all your components. Therefore, DI is the primary reason for highly decoupled components that you find in Spring applications. 2. What are the different types of dependency injection? Constructor-based dependency injection: It injects the dependency via aconstructor. This means that the required components are passed into a class at the time of instantiation. Setter-based dependency injection: It injects the dependency via a setter method. This involves calling setter methods on your beans after invokin

Spring Core Framework

1. How does Spring relates or differs from Java EE? Java EE that stands for Java Enterprise Edition is a specification. It is an effort for standardizing technologies to build Web and enterprise applications using the Java programming language. Vendors follow the Java EE specification to provide implementations, such as Web containers, application servers, message brokers, email systems, and so on. Programmers use Java EE implementations to develop applications. The power of Java EE comes with its own set of complexities. You have to deal with a large number of XML descriptors, create set of classes for even the most basic enterprise components, and so on. From the developers perspective, it took considerable effort and time to package, ship, deploy or redeploy, and start an application. Spring is one solution to such problems encountered in Java EE. Spring is a standalone framework for improvements and substitutions to Java EE. The Spring Framework is a Java platform su