top of page
  • Writer's pictureHeena

Is @ValueMapValue and @Inject same?

Updated: Dec 12, 2023

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 💛

389 views

Related Posts

See All

Comments


bottom of page