top of page
Writer's pictureHeena

Is @ValueMapValue and @Inject same?

Updated: May 2

Nope, it is not!


Following are the Injectors Available:

  1. Scripting Bindings

  2. ValueMap (We will specifically talk about this annotation on this post)

  3. Child Resource

  4. Request Attribute

  5. Resource path

  6. OSGi service

  7. Context-Aware Configuration

  8. Self

  9. 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.



That's all for today! If you've found this blog post informative or helpful, I’d greatly appreciate it if you could give it a like. It keeps me motivated 💛


Enjoying my ad-free blog? Support by buying me a coffee! I've kept this space ad-free, sponsoring it myself to maintain its purity. Your contribution would help keep the site afloat and ensure quality content. Thanks for being part of this ad-free community.

555 views

Related Posts

See All

Comentários


bottom of page