AD0-E123 practice question 6 of 10

A developer is using a Sling Model to apply some business logic to the values stored in the JCR before outputting them to the page, and all injected fields are optional for this model. What is the proper way to apply this behavior on the class level?

Full set: 50 questions
Answer options
A: 'default InjectionStrategy = Default Inject ionStrategy.OPTIONAL' Correct answer
B: 'requiredinjectionStrategy = FALSE'
C: 'injectionStrategy = InjectionStrategy.OPTIONAL
Correct Answer:
A. 'default InjectionStrategy = Default Inject ionStrategy.OPTIONAL'
Explanation

In Sling Models, the @DefaultInjectionStrategy annotation is used to specify the strategy for injecting fields into the model. When setting it to DefaultInjectionStrategy.OPTIONAL, it indicates that all injected fields in the Sling Model are optional and the model will not fail to instantiate if a field cannot be injected. This is a class-level annotation that affects the default injection behavior of all fields within the Sling Model.
Option B is incorrect because requiredInjectionStrategy is not a valid annotation property in Sling Models.
Option C is incorrect because injectionStrategy is not specified at the class level; it is used on the field level with the @Inject annotation.

Scroll to Top