Verified versions. JDK 25.0.5 (Temurin, LTS). Quarkus 3.40.1.1 with Quarkus LangChain4j 1.15.1 (which brings LangChain4j 1.23.0). Spring Boot 4.2.0 with Spring AI 2.1.0 (Spring Boot 4.2.0 and Spring AI 2.1.0 both reached Maven Central on 19 November 2026). Native images were built with Oracle GraalVM for JDK 25.0.4. Quarkus 4.0.1 is also GA (25 November 2026), but its LangChain4j extension, 2.0.0.CR1, is still a candidate release, so this post uses the Quarkus 3.40 line, where both halves are GA. Versions were read from maven-metadata.xml on Maven Central and from the build output.
What was and was not measured. There is no API key and no real model here. Both apps call a small deterministic stub that speaks the OpenAI wire format (source: StubLlmServer.java). So the post measures framework behaviour — declarations, request shapes, startup, memory, request overhead — and says nothing about answer quality, latency of a real model, or token cost. Timings came from a 2-CPU, 8 GB sandbox shared with other work, so treat them as indicative, not as a result.
Two apps, one assistant, and a model that is just a script
Both applications exposeGET /ask?q=... and do the same three things. They send a system prompt (“you are the support assistant of an online electronics shop”), they offer the model one tool, orderStatus(orderId), and for questions about returns, shipping or warranty they retrieve the best-matching of three short policy files and put it in front of the model. That is the shape of most real first AI features: a prompt, a tool and some retrieval.
The model is replaced by a stub that follows three rules: if the last message is a tool result, answer with it; if tools were offered and the question mentions an order number, ask for that tool call; otherwise echo the user message, which makes any injected policy text visible in the answer. Embeddings are hashed bag-of-words vectors, so retrieval is repeatable. The diagram shows the traffic; the sentence under it is the point.
Why a stub is a fair test here. Both frameworks are, underneath, an HTTP client that assembles a request and interprets the reply. Pointing both at the same scripted server removes everything that varies between model providers and leaves exactly the difference you would be choosing between. The cost is honesty about scope: a stub cannot tell you which framework’s default prompt gets better answers from a real model.Going deeper:
- The stub, including its three rules and the request recorder: StubLlmServer.java
- How to point either app at a real provider: change
base-urlandapi-keyin the twoapplication.propertiesfiles shown below. - Model-quality questions for small local models are covered in Tool Calling with Small Local Models.
Declaring the AI service: an interface versus a builder
In Quarkus LangChain4j you write an interface and annotate it. There is no class behind it; the extension generates the implementation. The system prompt is an annotation, the tools and the retrieval step are named in the annotation, and calling the service is calling a method.This is SupportAssistant.java from the Quarkus app (package, imports and the Javadoc omitted):
@RegisterAiService(retrievalAugmentor = PolicyRetrievalAugmentor.class, tools = OrderTools.class)
public interface SupportAssistant {
@SystemMessage("You are the support assistant of an online electronics shop. "
+ "Answer in one sentence. Use the order tool for order questions "
+ "and the supplied policy text for policy questions.")
String ask(String question);
}
Spring AI has no counterpart to “write an interface, get an implementation”. What it has is ChatClient, a fluent client you configure with a builder. The same three decisions — system prompt, tools, retrieval — are made in code instead of in an annotation. I searched the spring-ai-client-chat, spring-ai-model and spring-ai-vector-store-advisor 2.1.0 jars for anything resembling an AI-service or declarative-interface annotation and found none, so this is how it is today, not an omission in my code.
The Spring side, from AiConfig.java:
@Bean
ChatClient supportAssistant(ChatClient.Builder builder, VectorStore policyStore, OrderTools tools) {
return builder
.defaultSystem("You are the support assistant of an online electronics shop. "
+ "Answer in one sentence. Use the order tool for order questions "
+ "and the supplied policy text for policy questions.")
.defaultTools(tools)
.defaultAdvisors(QuestionAnswerAdvisor.builder(policyStore)
.searchRequest(SearchRequest.builder().topK(1).similarityThreshold(0.3).build())
.build())
.build();
}
The practical difference is where the assistant lives. In Quarkus it is a type you can inject, mock in a test and read at a glance. In Spring it is a configured ChatClient bean, and the controller (see AskController.java) calls prompt().user(q).call().content() every time. Neither is wrong. The interface form reads better as the number of assistants grows; the builder form is more flexible when you want to vary advisors or options per call.
Intermediate: what each side makes you write, line for line
Quarkus needs four small classes for the AI-specific part: the interface, the tool class, a store that embeds the policies when the app starts (PolicyStore.java) and a supplier that builds the retrieval pipeline (PolicyRetrievalAugmentor.java). Spring needs one configuration class and the tool class. The Quarkus count is higher because LangChain4j’s retrieval pipeline is explicit about the store, the embedding model and the augmentor; Spring’s QuestionAnswerAdvisor bundles retrieval and prompt injection into one object.
The dependency declarations are shorter than you might fear. Quarkus pulls in the OpenAI extension and the REST extension, and its two BOMs pin everything:
<dependency>
<groupId>io.quarkiverse.langchain4j</groupId>
<artifactId>quarkus-langchain4j-openai</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest</artifactId>
</dependency>
from pom.xml. Spring needs the OpenAI starter and, for the retrieval advisor, an artifact whose name changed: it is spring-ai-vector-store-advisor in 2.1.0, and my first build failed because I had written the older spring-ai-advisors-vector-store from memory. The BOM, not the docs prose, told me the new name.
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-vector-store-advisor</artifactId>
</dependency>
from pom.xml.
- Both apps’ wiring files: PolicyRetrievalAugmentor.java, AiConfig.java
- AI Services with chat memory and
@MemoryId, which this app leaves out on purpose: LangChain4j AI Services with Spring Boot 4 - Quarkus LangChain4j documentation and Spring AI reference
Tool calling: the same tool, slightly different on the wire
A tool is a method the model may ask your code to run. You describe it, the framework turns the description into a JSON schema and sends it with the request, the model replies with a tool call, the framework runs your method and sends the result back. That loop is why an order question costs two chat requests above. Here are the two versions of the same tool. Only the annotations differ: OrderTools.java for Quarkus and OrderTools.java for Spring AI. @Tool("Looks up the delivery status of a customer order by its order number")
public String orderStatus(@P("the numeric order number, for example 1001") String orderId) {
return "Order " + orderId + " is " + ORDERS.getOrDefault(orderId, "unknown");
}
@Tool(description = "Looks up the delivery status of a customer order by its order number")
public String orderStatus(@ToolParam(description = "the numeric order number, for example 1001") String orderId) {
return "Order " + orderId + " is " + ORDERS.getOrDefault(orderId, "unknown");
}
Asking “Where is my order 1001?” produces this in each app. The transcripts are written by the tests, which assert the same facts: 11-quarkus-tool-call.txt and 21-spring-tool-call.txt.
question: Where is my order 1001?
answer: STUB-ANSWER (from tool): Order 1001 is shipped on 2026-11-20, arriving in 2 days
chat requests sent to the stub for this question: 2
embedding requests for this question: 1
question: Where is my order 1001?
answer: STUB-ANSWER (from tool): "Order 1001 is shipped on 2026-11-20, arriving in 2 days"
chat requests sent to the stub for this question: 2
embedding requests for this question: 2
Look at the answers. The Spring one has quotation marks around the order text and the Quarkus one does not. That is not the stub: the stub echoes whatever the tool message contains. Spring AI serialises a tool’s return value as JSON, so a String goes to the model as "...". The recorded requests prove it, in 30-wire-summary.txt:
[assistant] 'None' tool_calls=[{"id": "call_stub_1", "type": "function", "function": {"name": "orderStatus", "arguments": "{\"orderId\":\"1001\"}"}}]
[tool] 'Order 1001 is shipped on 2026-11-20, arriving in 2 days'
[assistant] '' tool_calls=[{"id": "call_stub_1", "function": {"arguments": "{\"orderId\":\"1001\"}", "name": "orderStatus"}, "type": "function"}]
[tool] '"Order 1001 is shipped on 2026-11-20, arriving in 2 days"'
Fingerprint: stray quotes around a tool result. If a model’s answer quotes a tool result with surrounding double quotes, or starts treating a plain string as JSON, check how your framework serialises tool return values. Returning a small record instead of a bare string makes the format explicit on either side.
| On the wire | Quarkus LangChain4j 1.15.1 | Spring AI 2.1.0 |
|---|---|---|
| Tool schema | name, description, properties, required | the same, plus $schema, additionalProperties: false and strict: false |
| Tool result message | plain text | JSON-encoded (a string arrives quoted) |
| Extra request fields | frequency_penalty and presence_penalty sent as 0.0 | none beyond messages, model, tools |
| Assistant tool-call turn | content is null | content is an empty string |
| Declarations equal? | no (the recorder reports tool declaration identical: False) |
Intermediate: reading the recorded requests yourself
Everything above comes from raw request bodies the stub saved while each app answered two questions. They are in the repo as JSON, for example 003-chat.json and 003-chat.json, and wire_summary.py condenses them. The point of keeping them is that “what does my framework actually send?” is a question you can answer in five minutes, and the answer is often the explanation for a model behaving differently between two stacks.
To record your own, start the stub with -Dstub.record.dir=DIR as wire.sh does:
for side in quarkus spring; do
rm -f "$OUT/$side"/*.json
start_stub "$OUT/$side" || { echo "stub failed"; exit 1; }
if [ $side = quarkus ]; then start_quarkus; else start_spring; fi
rm -f "$OUT/$side"/*.json && curl -s localhost:18089/stats >/dev/null # drop the readiness probe
ask "Where is my order 1001?" > /dev/null
ask "How many days do I have to return an item?" > /dev/null
- Which small local models actually emit valid calls against a schema like this one: Tool Calling with Small Local Models
- All recorded request bodies: Quarkus request, Spring request
- OpenAI function-calling guide for the wire format both frameworks target
Retrieval: a retriever you assemble versus an advisor you attach
Retrieval-augmented generation here means: embed the three policy files once at startup, embed each question, find the closest file, and put its text in front of the model. In Quarkus that pipeline is plain LangChain4j, and the extension only needs to be told where to find it. This is the whole constructor of PolicyRetrievalAugmentor.java: PolicyRetrievalAugmentor(PolicyStore policies, EmbeddingModel embeddingModel) {
this.augmentor = DefaultRetrievalAugmentor.builder()
.contentRetriever(EmbeddingStoreContentRetriever.builder()
.embeddingStore(policies.store())
.embeddingModel(embeddingModel)
.maxResults(1)
.minScore(0.65) // LangChain4j scores are (cosine+1)/2, so 0.65 is cosine 0.3
.build())
.build();
}
In Spring AI it is the QuestionAnswerAdvisor you saw in AiConfig above, with a SearchRequest carrying topK and similarityThreshold. A policy question gives these transcripts, 12-quarkus-rag.txt and 22-spring-rag.txt:
question: How many days do I have to return an item?
answer: STUB-ANSWER (echo): How many days do I have to return an item? Answer using the following information: Returns policy: items can be returned within 30 days of delivery for a full refund. Items must be unused and in original packaging. Refunds are issued to the original payment method within 5 business days of the warehouse receiving the parcel.
chat requests sent to the stub for this question: 1
embedding requests for this question: 1
question: How many days do I have to return an item?
answer: STUB-ANSWER (echo): How many days do I have to return an item? Context information is below, surrounded by --------------------- --------------------- Returns policy: items can be returned within 30 days of delivery for a full refund. Items must be unused and in original packaging. Refunds are issued to the original payment method within 5 business days of the warehouse receiving the parcel. --------------------- Given the context and provided history information and not prior knowledge, reply to the user comment. If the answer is not in the context, inform the user that you can't answer the question.
chat requests sent to the stub for this question: 1
embedding requests for this question: 1
Both retrieved the right file (the returns policy) and left the shipping and warranty files out. The injected wording is different — LangChain4j appends “Answer using the following information:”, Spring AI wraps the text in its own “Context information is below” template — and Spring’s default template ends with an instruction to refuse if the answer is not in the context. That sentence is a prompt decision made for you; it is worth reading before you ship.
Trap: the two thresholds are on different scales. I first wroteminScore(0.3)on the Quarkus side to matchsimilarityThreshold(0.3)on the Spring side, and an unrelated question (“What is the weather in Paris”) still pulled in the returns policy. LangChain4j’s in-memory store reports a relevance score of (cosine + 1) / 2, so an unrelated, orthogonal question already scores 0.5. A cosine floor of 0.3 is aminScoreof 0.65, which is the value in the file. Spring’sSimpleVectorStorefilters on the cosine similarity itself. I found this by watching the test fail twice, not by reading the docs.
Difference worth knowing: what happens when nothing matches. For “Where is my order 1001?” nothing in the policy files is close enough in either app. Quarkus sent the user message untouched (line 4 of the wire summary). Spring still sent its context template with an empty context block (line 20), because the advisor always applies its template. The recorded request shows the template text; I did not test what a real model does with an empty block.One more observation from the transcripts: the order question made one embedding request in Quarkus and two in Spring. The recorded Spring requests explain it, because both chat requests of the tool loop (requests 1 and 2 in the wire summary) carry the retrieval template, so retrieval ran again on the second round trip. I have not traced the advisor chain to say exactly why; the counts and the requests are the evidence. With a real embedding API that second call would be billed.
Intermediate: the stub’s embeddings and why retrieval here is repeatable
The stub embeds text by lower-casing, dropping short and common words, crudely stripping “ed”, “ing” and “s”, hashing each remaining token into one of 1024 buckets and normalising the vector. It is nothing like a real embedding model, which is the point: it gives the same vector for the same text on every run, so the retrieval assertions in the tests are exact. The relevant lines are in StubLlmServer.java:
static ObjectNode vec(String s, int index) {
double[] v = new double[DIMS];
for (String t : s.toLowerCase().split("[^a-z0-9]+")) {
if (t.length() <= 2 || STOP.contains(t)) continue;
t = t.replaceAll("(ed|ing|s)$", ""); // crude stemming: return/returned/returns
v[Math.floorMod(t.hashCode(), DIMS)] += 1;
}
One consequence: a hashed stub tests your wiring, not your retrieval quality. When my first two unrelated test questions pulled in a policy file I suspected hash collisions; it was the score-scale trap above, and the fix was the threshold, not the stub. For retrieval quality see Advanced RAG with LangChain4j.
- Query compression, routing and Easy RAG on the LangChain4j side: Advanced RAG with LangChain4j
- Both apps’ tests, which assert retrieval and tool behaviour: Quarkus test, Spring test
- Spring AI RAG reference
Dev UI: what Quarkus shows you while you code
Runmvn quarkus:dev and Quarkus starts in development mode with live reload and a Dev UI at /q/dev-ui. With the LangChain4j extension installed, the Dev UI is generated with knowledge of your AI services. I started dev mode (it reported “Profile dev activated. Live Coding activated.”) and fetched the data file the extension generates, which is what its pages render. Saved as 50-quarkus-devui-data.txt:
$ curl -s localhost:18080/q/dev-ui/quarkus-langchain4j-core-data.js # while running: mvn quarkus:dev
// Generated by Quarkus during Build
export const systemMessages = ["You are the support assistant of an online electronics shop. Answer in one sentence. Use the order tool for order questions and the supplied policy text for policy questions."];
export const toolProviders = [];
export const aiservices = [{"clazz":"com.ankurm.qvs.SupportAssistant","tools":["com.ankurm.qvs.OrderTools"]}];
export const tools = [{"className":"com.ankurm.qvs.OrderTools","name":"orderStatus","description":"Looks up the delivery status of a customer order by its order number"}];
export const envVarMappings = {"OPENAI_API_KEY":"quarkus.langchain4j.openai.api-key"};
That is the build-time work from the diagram made visible: the AI service class, the tool it is allowed to call, its description and the system message are all known before a single request arrives. The file is generated by the build, so it cannot be stale relative to your code.
What I did and did not do: I confirmed the Dev UI is served and read its generated data. I did not drive the Chat or embedding-store pages through a browser. On the Spring side I looked for an equivalent that lists AI services and tools and did not find one in the starters I used; Spring Boot’s DevTools gives you restart-on-change, not an inventory of your AI wiring. If you know of one, that is a gap in my search, not a claim about Spring.
Delete it before production? Not necessarily: Quarkus documents the Dev UI as a dev-mode feature (I did not requestGoing deeper:/q/dev-uifrom the packaged JVM or native runs, so that is the documentation’s claim, not mine). Still, check thatquarkus.dev-uiis not enabled on a deployed instance, and keep any diagnostic endpoint you add out of release builds.
- The generated file as captured: 50-quarkus-devui-data.txt
- Quarkus Dev UI guide
Startup and memory: the numbers, and how much to trust them
Each app was launched as a plainjava -jar with default JVM flags, against the stub, seven times, alternating Quarkus and Spring so that both saw the same background load. For each launch the harness bench.py records the time until the port accepts connections, the time until the first answered request, the CPU time consumed by then, resident memory after that first answer, resident memory after 300 further requests, and median and 95th-percentile request latency. Median of seven runs, from 40-bench-jvm.txt:
| Metric (median of 7) | Quarkus 3.40, JVM | Spring Boot 4.2 / Spring AI 2.1, JVM | Quarkus 3.40, native |
|---|---|---|---|
| Launch to port open | 1545 ms | 4949 ms | 33 ms |
| Launch to first answer | 1851 ms | 5656 ms | 44 ms |
| CPU time used by first answer | 2980 ms | 10280 ms | 30 ms |
| RSS after first answer | 145.4 MiB | 306.5 MiB | 51.9 MiB |
| RSS after 300 requests | 172.4 MiB | 318.4 MiB | 96.7 MiB |
| Request latency p50 / p95 | 11.1 / 23.7 ms | 9.9 / 22.8 ms | 3.4 / 5.0 ms |
metric run1 run2 run3 run4 run5 run6 run7 median
t_port 2190 1594 1545 1386 1433 1454 1563 1545
t_first 2600 1922 1851 1641 1695 1735 1907 1851
cpu_first 3350 3030 2980 2720 2750 2860 3160 2980
rss_first 146.3 147.4 145.4 143.8 133.6 140.9 145.9 145.4
rss_after 172.4 173.5 168.2 174.1 170.1 172.5 169.5 172.4
p50 13.3 10.0 11.2 11.8 11.1 10.8 10.7 11.1
p95 28.2 23.2 24.3 23.7 23.9 18.2 21.7 23.7
Why not to over-read this. The host had two CPUs and was shared with other jobs; an earlier single-run attempt while the machine was busy (load average 11; not committed) showed Spring at 20.8 s to first answer, which is why the final run was interleaved and repeated on a quieter machine (load average 0.2 at the start). The first run of each app is slower than the rest in every table, which is the disk cache. The app does almost nothing, so a service with real dependencies will start slower on both sides. And these are median figures from seven runs, not a statistical test.Part of the Spring number is simply size on disk. The executable jar is 135,777,615 bytes with 120 nested jars, and 74,924,097 bytes of that is one dependency,
openai-java-core-4.101.0.jar, the OpenAI SDK that Spring AI 2.1.0’s OpenAI integration uses. The Quarkus fast-jar directory is about 28 MB. Both figures, and the self-reported startup lines, are in 43-sizes.txt:
Quarkus JVM (fast-jar) directory : 27964 KiB, 125 jars in lib/main
Spring Boot executable jar : 135777615 bytes, 120 nested jars
Quarkus native executable : 72223056 bytes
Quarkus native build time : 6m 25s (native-image step, 2 CPUs; a first attempt on a busier host took 15m 40s)
Largest Spring nested jar : openai-java-core-4.101.0.jar, 74924097 bytes
Quarkus native, self-reported : quarkus-app 1.0.0 native (powered by Quarkus 3.40.1.1) started in 0.087s
Quarkus dev mode, self-reported : quarkus-app 1.0.0 on JVM (powered by Quarkus 3.40.1.1) started in 4.303s. | Profile dev activated. Live Coding activated.
Intermediate: how the harness works, and what it does not control
The harness launches each app with -Dquarkus.http.port or -Dserver.port and base-url overrides so nothing collides with other processes, polls the TCP port every 5 ms, then repeats a first request until it returns 200. CPU time is read from /proc/PID/stat, memory from /proc/PID/status. The 300 follow-up requests rotate through a tool question, a policy question and an unrelated one.
It does not pin CPUs, drop caches, disable JIT tiers or tune the garbage collector, and both JVMs ran with the same default flags (the sandbox adds a few proxy system properties through JAVA_TOOL_OPTIONS to both). Tuning either side — class data sharing, -XX:TieredStopAtLevel=1, Spring AOT or Spring’s virtual-thread settings — would shift the JVM numbers, and I did not try it. The script, for reference:
p = subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
try:
while True:
try:
socket.create_connection(("localhost", PORT), timeout=0.05).close()
t_port = (time.perf_counter() - t0) * 1000
break
except OSError:
time.sleep(0.005)
if time.perf_counter() - t0 > 90:
raise SystemExit("app did not start")
while True:
try:
ask(QUESTIONS[0]); break
except Exception:
time.sleep(0.005)
t_first = (time.perf_counter() - t0) * 1000
- The same comparison without AI, three frameworks, more workloads: Spring Boot 4.1 vs Quarkus vs Micronaut: Benchmarked
- Rerun it yourself with run-all.sh
Native image: Quarkus built one, Spring AI did not on this machine
A native image compiles the whole application ahead of time into one executable, so there is no JVM warm-up. I built the Quarkus app with Oracle GraalVM for JDK 25.0.4 using-Dquarkus.native.enabled=true. The native-image step took 6 minutes 25 seconds on this 2-CPU machine (a first attempt while other jobs were running took 15 minutes 40 seconds). The result is a 72 MB executable that started in 87 ms according to Quarkus’s own log line (in the sizes file below) and answered its first request 44 ms after launch in the benchmark above, at about 52 MiB resident, which is where the third column of the table came from. Nothing about the Java source changed.
Trap: native images do not see files you did not declare. My first native build compiled and then crashed at startup with aFor Spring I ranNullPointerExceptioninPolicyStore.ingest:getResourceAsStreamreturned null because the policy text files were not embedded in the executable. The fix is one line in application.properties,quarkus.native.resources.includes=knowledge/*.txt. I did not save the failing log, so that failure is described, not captured.
mvn -Pnative -DskipTests native:compile with the same GraalVM. The build reported 4.87 GB of available memory, ran for well over half an hour and ended with java.lang.OutOfMemoryError: Java heap space. The captured lines are in 42-spring-native-attempt.txt:
Spring Boot 4.2.0 / Spring AI 2.1.0 native-image attempt (GraalVM for JDK 25.0.4, 2 CPUs, 8 GB host)
command: mvn -Pnative -DskipTests native:compile
Build resources:
- 4.87GB of memory (75.6% of system memory, in container)
- 2 thread(s) (100.0% of 2 available processor(s), determined at start)
Terminating due to java.lang.OutOfMemoryError: Java heap space
The Native Image build process ran out of memory.
This is a statement about this machine, not about Spring AI 2.1.0 in general: a host with more memory might build it, and I did not retry with a larger heap or add reachability hints for the OpenAI SDK. What I can say is that the Quarkus app with the same functionality built in under seven minutes on the same box and the Spring app did not build at all there. I also did not measure Spring in AOT mode on the JVM.
Intermediate: what a native build asks of you
Native image needs everything reachable at build time. Quarkus extensions register the reflection, resources and proxies they need, which is why the LangChain4j and OpenAI parts worked without any hints from me, and why the one thing I had to declare was my own resource files. Spring Boot generates hints through its AOT engine (the spring-aot directory appeared in target during my attempt), and the dependency set matters: this one pulls in a 75 MB SDK plus Netty, Kotlin and Tomcat.
Operationally, a native executable is a different artifact from your JAR: platform-specific, slower to build, and harder to debug. The Quarkus build in this module needs no code changes to switch between the two, and that is the part to weigh, not the headline startup number. The commands and the GraalVM requirement are in run-all.sh.
- Quarkus: building a native executable
- Spring Boot: GraalVM native images
- The memory and build-time table for serverless targets: Serverless AI Inference in Java
Which one should you pick?
Based only on what was run here:| If this matters most | Lean towards | Because (what I observed) |
|---|---|---|
| Small footprint or native image | Quarkus | Native built and ran at about 52–97 MiB; JVM mode used about half of Spring’s memory; Spring native did not build here |
| Declaring several assistants as typed interfaces | Quarkus LangChain4j | @RegisterAiService interface; Spring AI has no equivalent |
| You already run Spring and want AI as one more bean | Spring AI | one config class and one tool class; the rest of your stack stays the same |
| Fewer surprises in default prompts | Neither, read them | Spring injects its own template (even with empty context); LangChain4j adds its own line; both are prompt decisions |
| Steady-state request overhead | A tie | p50 within 1.2 ms of each other, against a stub |
Should you even choose on this basis? Probably not on startup alone. If your service already lives in the Spring ecosystem, its security, data and observability integrations are worth more than 4 seconds of startup you pay once per deployment, and a Spring AI feature costs you one class. If you are building something new where memory and cold start are billed (serverless, many small instances), the Quarkus numbers are real and the native path worked. And note the limits of this test: a stub model, one tiny workload, a shared 2-CPU host, no tuning on either side, no streaming, no chat memory. A real evaluation needs your model, your tools and your traffic.
Production checklist (both stacks)
- Timeouts and retries. Set the client timeout explicitly (
quarkus.langchain4j.openai.timeoutis in the Quarkus properties file; check the equivalent for your Spring AI client) and decide what a tool call should do when the model hangs. - Secrets. The API key in these files is the word “stub”. Use environment variables or a secret store, never a committed properties file.
- Prompt ownership. Read the default RAG templates of both frameworks (the transcripts above show them) and override them if you want to control refusal behaviour.
- Thresholds. Calibrate retrieval thresholds against your real embedding model, and remember that LangChain4j and Spring AI score on different scales.
- Tool results. Decide on a result format (plain text or a structured record) and test what the model does with it; quoted strings from Spring AI are the symptom to watch.
- Cost of the tool loop. Every tool call is a second chat request; with Spring AI’s advisor the retrieval step also repeated, so a billed embedding call can repeat as well.
- Native. Declare every resource and reflection target your own code needs; test the native binary, not just the JVM build.
- Diagnostics. Dev UI and any wire-recording tool are for development; keep them out of production builds.
- Versions. Quarkus LangChain4j 2.0.0 is at release-candidate stage for Quarkus 4; plan the upgrade rather than mixing lines.
Reproduce everything
The module is standalone (not part of the parent pom), so build it from its own directory:
export JAVA_HOME=/path/to/jdk-25
mvn install # builds both apps; the tests write output/11,12,21,22
scripts/start-stub.sh # stub LLM on :18089
java -Dquarkus.http.port=18080 -Dquarkus.langchain4j.openai.base-url=http://localhost:18089/v1 \
-jar quarkus-app/target/quarkus-app/quarkus-run.jar
curl 'localhost:18080/ask?q=Where+is+my+order+1001%3F'
from the module README.md. Everything in output/ is regenerated by run-all.sh; the native step needs GRAALVM_HOME. The tests, which start the stub themselves, are the source of the four transcripts that the post quotes first.
Further reading
- Companion repository module: langchain4j-demo / quarkus-vs-spring-ai
- Spring AI vs LangChain4j in 2026: Is Using Both Still Worth It?
- Spring Boot 4.1 vs Quarkus vs Micronaut: Benchmarked
- LangChain4j AI Services with Spring Boot 4
- Advanced RAG with LangChain4j
- Tool Calling with Small Local Models
- Quarkus LangChain4j documentation
- Spring AI reference documentation
- LangChain4j documentation
No Comments yet!