spring-projects/spring-ai · error
${msg.toString()}
Error message
${msg.toString()} What it means
CommonsLoggingStErrorListener is the StringTemplate (ST) error listener used by spring-ai-template-st. When the ST engine raises a runtime error while rendering a template, this listener logs it via Commons Logging: ERROR level for real errors, WARN level for missing-property errors, which are deliberately ignored otherwise. The message text is simply the ST engine's own error description.
Source
Thrown at spring-ai-template-st/src/main/java/org/springframework/ai/template/st/CommonsLoggingStErrorListener.java:49
private final Log logger;
/* package */ CommonsLoggingStErrorListener(Log logger) {
this.logger = logger;
}
@Override
public void compileTimeError(STMessage msg) {
logger.error(msg.toString());
}
@Override
public void runTimeError(STMessage msg) {
if (msg.error != ErrorType.NO_SUCH_PROPERTY) { // ignore these
logger.error(msg.toString());
}
else {
logger.warn(msg.toString());
}
}
@Override
public void IOError(STMessage msg) {
logger.error(msg.toString());
}
@Override
public void internalError(STMessage msg) {
logger.error(msg.toString());
}
}
View on GitHub (pinned to 98a7beda4f)
Solutions
- Read the logged ST message — it names the template and the exact property or operation that failed.
- Fix the placeholder/property path in the template so it matches the variables passed to render().
- Verify the model object exposes the referenced properties (public getters/fields accessible to ST).
- If the message is a NO_SUCH_PROPERTY warning, either add the missing variable to the model or use StTemplateRenderer validation to catch it upfront.
Example fix
// before: template references property that doesn't exist
StringTemplate st = new StringTemplate("Hello {userName.first}!"); // model has only 'user'
// after: align template with model
StringTemplate st = new StringTemplate("Hello {user}!"); Defensive patterns
Strategy: validation
Validate before calling
// verify placeholders match model keys before rendering
Set<String> tokens = extractPlaceholders(template);
if (!modelMap.keySet().containsAll(tokens)) { throw new IllegalArgumentException("unresolved placeholders: " + tokens); } Prevention
- Keep template property paths aligned with the actual model object structure.
- Render templates in tests with representative model objects.
- Use ValidationMode.THROW during development to surface issues early.
- Enable the ST error listener logging and check logs in CI.
When it happens
Trigger: Rendering an ST template (e.g. via StTemplateRenderer) that hits a runtime evaluation problem: referencing a property that does not exist on the model object, illegal reflective access on a property, or I/O errors — anything ST reports through RuntimeError.
Common situations: Prompt templates referencing variables with wrong property paths (obj.name where model has no 'name'); passing Maps instead of POJOs or vice versa; typos in template placeholders; using records/classes whose fields ST cannot access.
Related errors
- The template string is not valid.
- Method must not be null
- Method must have either 1 parameter (LoggingMessageNotificat
- Single parameter must be of type LoggingMessageNotification:
- First parameter must be of type LoggingLevel:
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/6ef23e3d35b9eb97.
Report an issue: GitHub.