Injections
and Scopes:
· If the resource class wants the data, instead of it is
getting the data from the request the jax-rs runtime itself identifies the
required data for the Resource class and injects the required data into the
resource class variables or parameters is nothing but injection.
· Jax-rs runtime supports three levels of injections
1. Attribute level
2.
Constructor level
3. Method
parameter level
· These injections will be based on the scope of the
resources, there will be two types of scopes
Request scope
o
If the scope is
singleton then jax-rs runtime can perform only the method parameter level
injection.
o
Because we are
creating the object of the Resource class and we are giving the object of the
Resource class to the jax-rs runtime.
o
So at the time of
we are creating the object itself the constructor will be called and attributes
will be initialized. So the jax-rs runtime can't performs the attribute level
and constructor level injections.
Singleton scope
o
If the scope is
request scope then we give only the class file to the runtime and runtime
itself creates the object of the Resource class.
o
At the time of
creating the object itself the attribute and constructor level injections will
be performed by the runtime after that it can also performs the method
parameter level injection.
· For managing the scopes of the Resources we should use third
or 7th way of bootstrapping approach.
For more information refer to
the program.

No comments:
Post a Comment