Sling Models with jakarta.annotation.PostConstruct fail on AEM 6.5 LTS
Sling Models on AEM 6.5 LTS fail to initialize when they use jakarta.annotation.PostConstruct which prevents post-construct logic from executing and disrupts component behavior. Updating the models to use javax.annotation.PostConstruct restores proper initialization and expected component functionality.
To resolve the issue, revert Sling Models to javax.annotation.PostConstruct.
Description description
Environment
- Adobe Experience Manager (AEM) Managed Services
- AEM 6.5 LTS with Sling Models
Issue/Symptoms
- Sling Model
@PostConstructmethods don’t execute after switching fromjakarta.annotation.PostConstruct. - Components that rely on post-construct logic fail to render or behave correctly.
- Models deploy sucessfully, but initialization logic doesn’t run.
Root Cause
AEM 6.5 LTS does not fully support Sling Models using the jakarta.annotation namespace. The Sling Models implementation recognizes only javax.annotation.PostConstruct, so jakarta.annotation.PostConstruct methods are not executed during model initialization.
Resolution resolution
Steps to resolve:
- Update all Sling Model classes to use
javax.annotation.PostConstructinstead ofjakarta.annotation.PostConstruct. - Remove all
jakarta.*imports related to@PostConstructfrom all Sling Model classes. - Review your project dependencies (for example,
pom.xml) and confirm that onlyjavaxdependencies are used for annotations relevant to Sling Models. - Rebuild the project to ensure the dependency and import changes are correctly applied.
- Deploy the updated code and verify that the bundle containing the Sling Models is in the Active state in the
/system/console/bundles. - Verify that all Sling Models classes are listed in
/system/console/status-slingmodels. - Confirm that
@PostConstructmethods are invoked successfully, and components behave as expected.
Notes:
- AEM 6.5 LTS does not support Sling artifacts migrated to the
jakarta.*namespace, includingjakarta-based @PostConstruct. - This behavior aligns with reference implementations such as the AEM WKND Sites Project, which continues to use
javax.annotation.PostConstructon AEM 6.5 LTS.
Related reading
recommendation-more-help
3d58f420-19b5-47a0-a122-5c9dab55ec7f