Heena Shirke
Is @ValueMapValue and @Inject same?
Nope, it is not!
Following are the Injectors Available:
Scripting Bindings
ValueMap (We will specifically talk about this annotation on this post)
Child Resource
Request Attribute
Resource path
OSGi service
Context-Aware Configuration
Self
Sling Object
@Inject iterates through all available injectors and injects the first non-null value provided by an injector. This lead to unpredictable behavior, although the order is well-defined. Also, this turned out to be a performance bottleneck, especially if (optional) injections were not successful, and then all other injectors have to be tried.
Whereas, @ValueMapValue injects ValueMap value taken from the adapted resource (either taking from the adapted resource or the resource of the adapted SlingHttpServletRequest). If the name is not set the name is derived from the method/field name.
Thus, usage of @ValueMapValue is preferred as it specifically injects the ValueMap injector and doesn't iterate through all the available injectors.