Backend knowledge Flashcards
What is the purpose of the @Autowired annotation?
The @Autowired annotation is used for automatic dependency injection in Spring Boot. It tells Spring to automatically inject a bean or component into a class where @Autowired is used
What are different methods of dependency injection in Spring Boot and which is the preferred one?
Constructor injection - preferred
Field Injection
Setter Injection
What is the advantage of using setter dependency injection?
Setter injection allows for optional dependencies and the ability to change dependencies at runtime
What is IoC (Inversion of Control)?
Inversion of Control (IoC) is a design principle where a framework controls the flow and dependencies of your application.
What is Singleton pattern and how is it utilized in Spring Boot?
The Singleton pattern ensures that a class has only one instance, and it provides a global point of access to that instance. In Spring Boot, beans like Services and Controllers are singletons by default, meaning there’s only one instance of a bean, and it’s shared across the application.
What is Factory Pattern?
The Factory Pattern is a creational design pattern that provides an interface for creating objects but lets subclasses alter the type of objects that will be created.
What is Observer Pattern?
The Observer Pattern is a behavioral design pattern where an object (the subject) maintains a list of its dependents (observers) and notifies them of state changes, allowing multiple objects to stay in sync with the subject’s state.
Explain Spring MVC
Spring MVC (Model-View-Controller) is a framework within the Spring ecosystem for building web applications. It separates an application into three interconnected components (Model, View, Controller).
Spring MVC simplifies web application development by providing a structured way to handle HTTP requests and render responses.
Explain @Configuration annotation
Spring Configuration annotation indicates that the class has @Bean definition methods. So Spring container can process the class and generate Spring Beans to be used in the application.
How can we inject value from properties file into Spring Boot class variable?
We use @Value annotation
How can you enhance the security of an application?
We can use authentication provider like Keycloak.
What practice can help mitigate security risks when processing user-provided data in your application?
Validation of user sent data
How can you define an endpoint in Controller Class in Spring Boot? (any method)
Example: @GetMapping(“/path”)
How do you typically organize the components and layers in a Spring Boot application to maintain a clean and structured codebase?
We divide it into Controller, Service, Repository, Model