WT_UNIT4
WT_UNIT4
Tarun Kumar
021) Sharma
WEB TECHNOLOGY(KCA-
021)
UNIT-4
(Spring)
SPRING CORE BASICS
Spring Core Basic:
It means that one class is unable to perform its task without the
support other class. This concept is known as dependency, where
one class needs the object of other class. This object is created
manually by the programmer with the help of new keyword, where
as spring framework inject the required object at runtime with the
DEPENDENCY INJECTION
CONCEPTS
Dependency Injection (DI) : it is a design pattern used to remove
hard-coded dependencies and make the code loosely coupled,
maintainable and testable.
The Spring IoC container then injects these dependencies when the
object is created or initialized. This approach promotes loose
coupling and enhances the testability, flexibility, and
maintainability of the application.
SPRING INVERSION OF
CONTROL (IOC)
Instead of a bean creating or locating its own dependencies (e.g.,
by directly instantiating other classes), the control is inverted. In
this model, the container is responsible for supplying the
dependencies to the bean at the time of its creation.
Join Point:
A join point is just a specific point during your program's execution
—usually when a method is called. In Spring AOP, every time a
method is run, it’s considered a join point. You can use an aspect to
AOP CONCEPTS AND
TERMINOLOGY
Advice is the action that an aspect performs at certain points in
your code — like running something before, after, or around a
method. In Spring AOP, advice works like an interceptor that wraps
around the method being called.
Note: Here, Spring will automatically inject the engine bean into car using the
constructor. This means you don’t need to specify the constructor-arg
manually — Spring figures it out based on the constructor type.
EXAMPLE WITHOUT AUTO
WIRING
Manual Configuration in XML
Note: Here, Spring will automatically inject the engine bean into car using the
setter method.
EXAMPLE WITHOUT AUTO
WIRING
Manual Configuration in XML
<bean id="exampleInitBean"
class="examples.AnotherExampleBean"/>
@Bean
public MyServiceImpl myService() {
return new MyServiceImpl();
}
}
The preceding AppConfig class is equivalent to the following
Spring <beans/> XML:
<beans>
<bean id="myService"
class="com.acme.services.MyServiceImpl"/>