Apache Camel Choice组件When条件判断报错求助:SimpleIllegalSyntaxException
Let's break down why you're hitting that error first:
SimpleIllegalSyntaxException: is operator cannot find class with name: VS at location 22 ${body.recType} is 'VS'
In Apache Camel's Simple language, the is operator is designed to check object types, not string equality. When you write ${body.recType} is 'VS', Camel tries to locate a class named VS (which doesn't exist in your codebase), hence the syntax exception.
Valid Solutions to Compare String Values
Here are a few reliable ways to check if recType matches the constant 'VS':
1. Use the == operator for string equality
The Simple language uses == to compare string values directly. Update your when condition like this:
from("direct:processAccounts") .process(filterProcessor) .split(simple("${body}")) .choice() .when(simple("${body.recType} == 'VS'")) .process((exchange) -> { log.info("VS:"); }) .otherwise() .to("stream:out");
2. Use the explicit eq function
For more readable equality checks, you can use the eq function instead:
.when(simple("${body.recType} eq 'VS'"))
3. Type-safe Java Predicate (avoid Simple language parsing)
If you want to skip Simple language syntax entirely and use type-safe code, you can directly check the value via the entity's getter method:
.when(exchange -> { Records record = exchange.getIn().getBody(Records.class); return "VS".equals(record.getRecType()); })
This approach eliminates any parsing-related errors and gives you full control over the comparison logic.
Quick Reminder
Keep these Simple language rules in mind for future use:
is= checks if an object is an instance of a specific class (e.g.,${body} is com.example.Records)==/eq= checks value equality for strings, numbers, and primitives
内容的提问来源于stack exchange,提问作者Jericho

