- Get link
- X
- Other Apps
1) What is Spring Framework (Spring 6)?
Spring Framework is a comprehensive programming and configuration model for Java-based enterprise applications. As of Spring 6, it supports:
-
Java 17+ as a baseline
-
Jakarta EE 9 (e.g.,
jakarta.servlet
instead ofjavax.servlet
) -
Native support for GraalVM and AOT (Ahead-of-Time) compilation
-
Enhanced observability and performance
2) What are the advantages of Spring Framework 6?
-
Loose Coupling & Dependency Injection (DI)
-
Predefined Templates (JdbcTemplate, RestTemplate, etc.)
-
Faster Development
-
Declarative Programming (with annotations)
-
Lightweight & Modular
-
Native Compilation Support (via GraalVM)
-
Better Observability (Micrometer support)
-
Improved Testing Support
3) What are the modules in Spring 6?
-
Core Container: Beans, Core, Context, SpEL
-
Data Access/Integration: JDBC, ORM, Transactions, JMS
-
Web: Spring MVC, WebFlux (reactive)
-
AOP, Aspects and Instrumentation
-
Test: JUnit 5, Mockito, Spring TestContext
-
Native: GraalVM and AOT support
4) What is IoC and DI?
IoC (Inversion of Control) is a design principle where control of object creation is inverted to a container (Spring).
DI (Dependency Injection) is how Spring implements IoC.
Without DI:
class Employee { Address address = new Address(); // tightly coupled
}
With DI:
class Employee { Address address;
public Employee(Address address) {
this.address = address; // loosely coupled
}
}
5) What is the role of IoC Container in Spring?
The IoC container is responsible for:
-
Creating objects
-
Configuring them
-
Wiring dependencies
-
Managing lifecycle
6) Types of IoC Containers in Spring:
-
BeanFactory
: Basic container -
ApplicationContext
: More feature-rich, supports internationalization, AOP, etc.
7) Difference: BeanFactory vs ApplicationContext
Feature | BeanFactory | ApplicationContext |
---|---|---|
Lazy Initialization | Yes | No (by default) |
AOP Support | No | Yes |
i18n Support | No | Yes |
Event Propagation | No | Yes |
Annotation Config | Limited | Full support |
8) Constructor vs Setter Injection
Criteria | Constructor Injection | Setter Injection |
---|---|---|
Partial Injection | Not possible | Possible |
Overriding Values | No | Yes |
Immutable Dependency | Yes | No |
Use Case | Mandatory dependencies | Optional dependencies |
9) Autowiring in Spring
Autowiring automatically injects beans without manual configuration.
Modes:
Mode | Description |
---|---|
no | Default, no autowiring |
byName | Matches bean by property name |
byType | Matches bean by type |
constructor | Injects using constructor |
Note: XML-based autowiring is deprecated in favor of
@Autowired
,@Inject
,@Qualifier
.
10) Bean Scopes in Spring 6
Scope | Description |
---|---|
singleton | Single shared instance (default) |
prototype | New instance per request |
request | One per HTTP request (web only) |
session | One per HTTP session |
application | One per ServletContext |
websocket | One per WebSocket |
11) What is the default bean scope?
The singleton scope is the default.
12) Are Singleton Beans Thread-Safe?
No, Spring singleton beans are not thread-safe by default. You must handle synchronization explicitly.
13) What is Dependency Injection (DI)?
DI is a design pattern that promotes loose coupling by injecting dependencies into objects rather than letting objects construct their dependencies.
14) What is a ViewResolver in Spring MVC?
A ViewResolver
maps logical view names returned by controllers to actual views (e.g., JSPs, Thymeleaf, etc.).
15) View Resolver Pattern
-
Controller returns view name (e.g., "home")
-
ViewResolver maps it to an actual view (
/WEB-INF/views/home.jsp
orhome.html
) -
Supports pluggable view technologies (JSP, Thymeleaf, PDF, Excel)
16) Spring Transaction Management Types
-
Programmatic – using
TransactionTemplate
orPlatformTransactionManager
-
Declarative – using
@Transactional
Declarative is recommended in most cases.
17) Advantages of JdbcTemplate
-
Reduces boilerplate code (no need to handle connection, statement, result set manually)
-
Handles exceptions and resources automatically
18) Key Classes in Spring JDBC API
-
JdbcTemplate
-
NamedParameterJdbcTemplate
-
SimpleJdbcInsert
-
SimpleJdbcCall
19) How to fetch records using JdbcTemplate
Use query()
method with:
-
RowMapper
: For row-wise mapping -
ResultSetExtractor
: For custom extraction logic
20) Advantage of NamedParameterJdbcTemplate
- Improves readability using named parameters instead of
?
, e.g.:
String sql = "SELECT * FROM users WHERE name = :name";
21) What is the front controller in Spring MVC?
DispatcherServlet
acts as the front controller that routes requests to appropriate controllers and views.
22) What is AOP?
Aspect-Oriented Programming is a way to modularize cross-cutting concerns like logging, security, and transactions into reusable modules called aspects.
23) Advantages of Spring AOP
-
Modularizes repetitive concerns
-
Reduces code duplication
-
Dynamic proxy-based implementation
24) Key AOP Terminology
Term | Description |
---|---|
JoinPoint | A point during execution (e.g., method call) |
Advice | Action at a JoinPoint (e.g., before, after) |
Pointcut | Expression to select JoinPoints |
Aspect | Class with Advices and Pointcuts |
Target | Actual object being advised |
Proxy | Wrapper created to apply AOP |
Weaving | Applying aspects to target objects |
- Get link
- X
- Other Apps
Comments
Post a Comment