Hello
I am curious about how Sling handles Sling Model.
Say, I instantiate a Sling Model in Sightly, then a PostConstruct is called. Why not a constructor?
Solved! Go to Solution.
Views
Replies
Total Likes
The @PostConstruct annotation essentially serves as an alternative to a constructor. If you were to employ a constructor in your model, you would observe that, upon its execution, the fields annotated with @Inject are still unassigned. Attempting further initialization with these fields at this point would result in a NullPointerException.
The entire sequence unfolds as follows:
new MyModel()
).Sling model annotations: Basics – Adobe Experience Manager Blog (techrevel.blog) (Refer to PostConstruct Annotation section)
The @PostConstruct annotation essentially serves as an alternative to a constructor. If you were to employ a constructor in your model, you would observe that, upon its execution, the fields annotated with @Inject are still unassigned. Attempting further initialization with these fields at this point would result in a NullPointerException.
The entire sequence unfolds as follows:
new MyModel()
).Sling model annotations: Basics – Adobe Experience Manager Blog (techrevel.blog) (Refer to PostConstruct Annotation section)