The first time I tried to ship an AI feature in a Spring Boot service, I reached for LangChain4j because I knew Python’s LangChain and wanted the Java equivalent. It worked — but the setup was verbose. Six months later I tried the same with Spring AI and had streaming chat running in forty minutes. The problem was that Spring AI’s agent and tool-calling support was too limited for what I needed. The answer, annoyingly, was to use both.
This guide is the result of running both frameworks in a production order-management assistant — Spring AI 1.0.0-M6 with LangChain4j 0.33.0 on Spring Boot 3.4.1, Java 21.0.3, backed by PostgreSQL 16 with PGVector 0.7.0. Spring AI handles the ChatClient, RAG pipeline, and Micrometer observability. LangChain4j handles the agent loop and tool registry where its control over iteration and retries is genuinely superior. The division is deliberate, not accidental.
Tag Archives: AI
10 AI Prompts for Designing Java Microservices
Microservices architecture introduces a class of problems that monoliths simply do not have: partial failures, distributed transactions, network latency between services, schema versioning across independent deployments, and the operational complexity of coordinating dozens of independently deployed components. The first time I designed a circuit breaker configuration for a production service, I guessed the thresholds. The circuit opened too aggressively during a transient network hiccup and caused more downtime than the downstream failure it was meant to protect against. The second time, I ran the numbers from the downstream service’s SLA and worked backwards. There was no tutorial that taught me to do that — I learned it the hard way. These 10 prompts encode the questions you need to answer before you configure Resilience4j, write an OpenAPI contract, or design a Kafka consumer group — so the AI produces configuration that fits your actual failure scenario rather than a generic example. Getting these patterns right requires both architectural experience and fluency with a large surface area of libraries and specifications. AI assistants are well-positioned here — they know the Resilience4j API, the OpenAPI specification, the Kafka consumer group model, the Micrometer tracing API, and the Kubernetes health probe semantics.
This post gives you 10 copy-paste AI prompts for designing Java microservices. Each prompt targets a specific cross-cutting architecture concern and is engineered to produce production-grade, runnable output rather than pseudocode.
For related reading, see 10 AI Prompts for Spring Boot Development and the Java series. For the Spring AI and LLM Gateway patterns, see the LLM Gateway for Java Microservices post.
Continue reading 10 AI Prompts for Designing Java Microservices10 AI Prompts for Java Performance Optimization
Java performance problems are notoriously difficult to diagnose: they are intermittent, load-dependent, and often invisible until a production incident. Reading a GC log, interpreting a thread dump, or identifying a memory leak in a heap dump requires both tool knowledge and pattern recognition that most developers only acquire after encountering these problems in production. I have sat in enough Java postmortems to recognise the pattern: the engineer who fixed the GC pause issue had seen that exact pause signature before. The one who found the connection pool leak recognised the symptom from a previous incident. That experience is transferable to an AI assistant if you provide the right diagnostic artifact in the right format — the AI knows the GC log structure, the HikariCP timeout messages, the thread dump markers for a deadlock. These 10 prompts are structured around that transfer: they tell you exactly which artifact to collect and how to present it for maximum diagnostic accuracy.
For related content, see Virtual Threads vs Platform Threads — Benchmarks and Code and 10 AI Prompts to Review and Improve Java Code Quality.
Continue reading 10 AI Prompts for Java Performance Optimization10 AI Prompts for Hibernate and JPA
Hibernate is powerful and largely invisible when it works — and deeply confusing when it does not. N+1 queries, LazyInitializationException, detached entity exceptions, first-level cache surprises, and migration scripts that silently break the schema are problems that most Java developers encounter repeatedly throughout their careers.
I started keeping a list of Hibernate bugs that slipped through review in a large Spring Boot 3 codebase — things that passed all unit tests, passed all integration tests, and only surfaced under production load or after a schema migration. After a dozen entries the pattern was clear: almost all of them were diagnosable by AI if you pasted the right context. The problem was knowing which context to paste. These 10 prompts encode that knowledge — each one specifies exactly what diagnostic data to provide, so the AI can reason about the real problem rather than the surface symptom. AI assistants handle Hibernate well: they know the JPA specification, the Hibernate-specific extensions, the Spring Data abstractions, and the performance implications of every mapping decision.
This post gives you 10 copy-paste AI prompts for Hibernate and JPA development. Each prompt is designed to produce production-quality output — not tutorial-level simplifications — and includes enough context for the AI to reason about the trade-offs specific to your use case.
For foundational reading, see the Hibernate Tutorials series. For complementary AI prompts, see 10 AI Prompts to Review and Improve Java Code Quality.
Continue reading 10 AI Prompts for Hibernate and JPA10 AI Prompts to Review and Improve Java Code Quality
Code review is the most effective quality gate in software development — but it is also the most time-constrained. Reviewers scan for obvious bugs and style issues, but subtle problems like carrier pinning inside synchronized blocks, hidden N+1 queries in service layers, and resource leaks in non-obvious code paths regularly slip through. I built these prompts after a quarter where our team’s post-incident reviews kept surfacing the same categories of bug: thread-safety assumptions broken by virtual threads, transaction boundaries that worked in tests but silently failed under concurrent load, and SOLID violations that only became painful when the code needed to be extended. The pattern was clear — these were not one-off mistakes, they were the class of problem that human reviewers consistently miss because they require holding the entire call graph in working memory at once. AI assistants handle this better. These 10 prompts are structured to extract that analysis reliably.
This post gives you 10 AI prompts engineered for Java code quality review. Each prompt targets a specific class of problem, provides a structured diagnosis checklist, and requests actionable fixes rather than just observations. Use them before a pull request, as part of a legacy codebase audit, or as a learning tool when onboarding to an unfamiliar module.
For complementary content, see 10 AI Prompts to Generate JUnit 6 Tests and Virtual Threads vs Platform Threads — Benchmarks and Code.
Continue reading 10 AI Prompts to Review and Improve Java Code Quality10 AI Prompts for Spring Boot Development
Spring Boot’s convention-over-configuration model is genuinely one of the best things to happen to Java productivity — and also the source of the most confusing production bugs I have debugged. Autoconfiguration fires conditions you never set consciously. Security filters block requests for reasons that aren’t logged. Default settings that are fine for development (open-in-view=true, 10-connection HikariCP pool, permissive CORS) quietly create problems at scale.
I built this prompt set specifically for gaps I kept hitting when using AI assistants for Spring Boot work. Generic prompts produce boilerplate that compiles but ignores your Spring Boot version, your actual security requirements, and the performance implications of the defaults chosen. These 10 prompts are engineered around context: they ask you to provide your Spring Boot version, your business rules, and your actual failure scenario, so the AI produces output you can actually commit. Tested against Claude Sonnet 4 and GPT-4o with Spring Boot 3.4 and Spring Security 7.
This post gives you 10 copy-paste AI prompts for Spring Boot development, covering the full lifecycle from initial scaffolding to production hardening and version migration. Each prompt is engineered to give the AI enough context to produce immediately usable, production-quality output.
For background on the Spring ecosystem, see the Java category. For complementary testing prompts, see 10 AI Prompts to Generate JUnit 6 Tests for New Projects.
LLM Gateway for Java Microservices — Complete Runnable Code & Demo
This is the companion code post to ← The LLM Gateway Pattern for Java Microservices. That article explains the design decisions behind each layer. This post gives you the complete project — every file, ready to clone and run.
Prerequisites
- Java 21+ and Maven 3.9+
- Docker and Docker Compose (for Redis)
- An OpenAI API key — required. Anthropic and Ollama keys are optional; the gateway falls back automatically if they are absent.
Project Structure
llm-gateway/
├── docker-compose.yml
├── pom.xml
└── src/main/
├── java/com/example/gateway/
│ ├── LlmGatewayApplication.java
│ ├── cache/
│ │ ├── CacheEntry.java
│ │ └── SemanticCache.java
│ ├── controller/
│ │ └── LlmGatewayController.java
│ ├── cost/
│ │ └── CostTracker.java
│ ├── model/
│ │ ├── LlmGatewayRequest.java
│ │ └── LlmGatewayResponse.java
│ ├── orchestrator/
│ │ ├── LlmGatewayOrchestrator.java
│ │ └── RateLimitExceededException.java
│ ├── ratelimit/
│ │ ├── TenantTier.java
│ │ ├── TenantTierRepository.java
│ │ └── TokenBudgetRateLimiter.java
│ └── registry/
│ ├── AllProvidersUnavailableException.java
│ ├── LlmProviderRegistry.java
│ └── ResilientProviderCaller.java
└── resources/
└── application.yml