What is bean wiring?
Combining together beans within the Spring container is known as bean wiring or wiring. When
wiring beans, you should tell the container what beans are needed and how the
container should use dependency injection to tie them together.
How do add a bean in spring application?
<?xml version=”1.0″ encoding=”UTF-8″?> <!DOCTYPE beans PUBLIC “-//SPRING//DTD
BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”> <beans> <bean id=”foo” class=”com.act.Foo”/> <bean id=”bar” class=”com.act.Bar”/> </beans> |
In the bean tag the id attribute specifies the bean
name and the class attribute specifies the fully qualified class name.
What are singleton beans and how can you create prototype beans?
Beans defined in spring framework are singleton
beans. There is an attribute in bean tag named ‘singleton’ if specified
true then bean becomes singleton and if set to false then the bean becomes a
prototype bean. By default it is set to true. So, all the beans in spring
framework are by default singleton beans.
<beans> <bean id=”bar” class=”com.act.Foo” singleton=”false”/> </beans> |
What are the important beans lifecycle methods?
There are two important bean lifecycle methods. The
first one is setup which is called when the bean is loaded in to the container.
The second method is the teardown method which is called when the bean is
unloaded from the container.
How can you override beans default lifecycle methods?
The bean tag has two more important attributes with
which you can define your own custom initialization and destroy methods. Here I
have shown a small demonstration. Two new methods fooSetup
and fooTeardown are to be added to your Foo class.
<beans> <bean id=”bar” class=”com.act.Foo” init-method=”fooSetup”
destroy=”fooTeardown”/> </beans> |
What are Inner Beans?
When wiring beans, if a bean element is embedded to
a property tag directly, then that bean is said to the Inner Bean. The drawback
of this bean is that it cannot be reused anywhere else.
What are the different types of bean injections?
There are two types of bean injections.
1. By setter
2. By constructor
What is Auto wiring?
You can wire the beans as you wish. But spring framework
also does this work for you. It can auto wire the related beans together. All
you have to do is just set the autowire attribute of
bean tag to an autowire type.
<beans> <bean id=”bar” class=”com.act.Foo” Autowire=”autowire type”/> </beans> |
What are different types of Autowire types?
There are four different types by which autowiring can be done.
byName
byType
constructor
autodetect
What are the different types of events related to Listeners?
There are a lot of events related to ApplicationContext of spring framework. All the
events are subclasses of org.springframework.context.Application-Event.
They are
ContextClosedEvent – This is fired when the context is closed.
ContextRefreshedEvent – This is fired when the context is initialized or refreshed.
RequestHandledEvent – This is fired when the web context handles any request.
What is an Aspect?
An aspect is the cross-cutting functionality that you
are implementing. It is the aspect of your application you are modularizing. An
example of an aspect is logging. Logging is something that is required
throughout an application. However, because applications tend to be broken down
into layers based on functionality, reusing a logging module through inheritance does not make sense. However, you can create a logging aspect and
apply it throughout your application using AOP.
What is a Jointpoint?
A joinpoint is a point in
the execution of the application where an aspect can be plugged in. This point
could be a method being called, an exception being thrown, or even a field
being modified. These are the points where your aspect’s code can be inserted
into the normal flow of your application to add new behavior.
What is an Advice?
Advice is the implementation of an aspect. It is
something like telling your application of a new behavior. Generally, and
advice is inserted into an application at joinpoints.
What is a Pointcut?
A pointcut is something
that defines at what joinpoints an advice should be
applied. Advices can be applied at any joinpoint that
is supported by the AOP framework. These Pointcuts
allow you to specify where the advice can be applied.
What is an Introduction in AOP?
An introduction allows the user to add new methods
or attributes to an existing class. This can then be introduced to an existing
class without having to change the structure of the class, but give them the
new behavior and state.
What is a Target?
A target is the class that is being advised. The
class can be a third party class or your own class to which you want to add
your own custom behavior. By using the concepts of AOP, the target class isfree to center on its major concern, unaware to any
advice that is being applied.
What is a Proxy?
A proxy is an object that is created after applying
advice to a target object. When you think of client objects the target object
and the proxy object are the same.
What is meant by Weaving?
The process of applying aspects to a target object
to create a new proxy object is called as Weaving. The aspects are woven into
the target object at the specified joinpoints.
What are the different points where weaving can be applied?
Compile Time
Class load Time
Runtime
No comments:
Post a Comment