Expand my Community achievements bar.

AEM Model cannot be correctly instantiated by the Use API

Avatar

Level 2

Hi There,

 

I have been using AEM CaaS SDK locally since long, but recently it started showing blank sites pages. When logs were looked into, it was found to not be able to instantiate an old AEM model with following error

 

org.apache.sling.scripting.sightly.SightlyException: Identifier com.xyz.core.models.SEOModel cannot be correctly instantiated by the Use API

When I looked into stack trace it did not give any details on issue it is facing except 

 

Caused by: java.lang.ClassNotFoundException: com.xyz.core.models.SEOModel
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at org.apache.sling.commons.fsclassloader.impl.FSDynamicClassLoader.loadClass(FSDynamicClassLoader.java:58) [org.apache.sling.commons.fsclassloader:1.0.14]
	at org.apache.sling.scripting.sightly.impl.engine.extension.use.JavaUseProvider.provide(JavaUseProvider.java:129) [org.apache.sling.scripting.sightly:1.4.24.140]
	at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:71) [org.apache.sling.scripting.sightly:1.4.24.140]
	... 228 common frames omitted

 It just says ClassNotFoundException, that's it. Class is there and its an old model, which was not changed recently and suddenly it has stopped being resolved. Here are snippet from model

 

```

package com.xyz.core.models;
// LOC omitted 
@Model(adaptables = { SlingHttpServletRequest.class,
Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class SEOModel {

```

File is com/xyz/core/models/ folder. 

 

Help is appreciated

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

3 Replies

Avatar

Level 9

The ClassNotFoundException for SEOModel in your AEM CaaS SDK environment typically indicates deployment or class visibility issues. 

1) Verify Bundle Deployment

  • Check /system/console/bundles to confirm:

    • Your core bundle (containing SEOModel) is Active.

    • No unresolved dependencies or import errors exist.

  • If inactive: Redeploy the bundle via Maven (mvn clean install -PautoInstallBundle) and monitor the OSGi console for errors

2) Validate Class Packaging

  • Inspect the compiled JAR/WAR file to ensure:

    • SEOModel.class exists in com/xyz/core/models/.

    • The package structure matches the Java file’s declared package.

  • Common causes:

    • Incorrect <Build-OutputDirectory> in Maven’s POM.

    • .gitignore/build filters excluding the class

3) Check for Hidden Exceptions

  • Add debug logs to @PostConstruct methods in SEOModel to identify initialization failures (e.g., null injections or uncaught exceptions)419.

  • Review error.log for stack traces occurring before the ClassNotFoundException, which may point to:

    • Missing OSGi services (e.g., @OSGiService-annotated fields).

    • Invalid resource adaptations (e.g., Resource.adaptTo(SEOModel.class) failing)

4) Temporary Workaround

If the issue persists, use the ModelFactory directly for better error reporting:

try {
    SEOModel model = modelFactory.createModel(request, SEOModel.class);
} catch (Exception e) {
    logger.error("Model instantiation failed: ", e);
}

This bypasses the adaptTo() method’s silent failures

Avatar

Community Advisor

Hi @bagwanpankaj 

Did you created this as a new Model, or was it working before but stopped working now?

In case it was working before then check the references, logic in sling model.

 

If it is a new model then check the project osgi bundle and see what is the status of the model?

 

arunpatidar_0-1749569235778.png

 

Arun Patidar

AEM LinksLinkedIn

Avatar

Community Advisor

Hi @bagwanpankaj 

 

Quick questions 

1. Was this working previously and its not working now?

2. Is their any recent version updates in pom.xml file

3. Can you match or Increase your sdk version to the one version mentioned in the parent pom.xml file.

 

Ideally with out any recent changes to the code the model classes doesn't fail