---
name: spring-integration
description: Integrate JasperReports into Spring services and HTTP endpoints, including packaged resources, request isolation, response headers, and safe error mapping. Use for Spring web integration, not standalone Java lifecycle code or JRXML design.
---
# Integrate JasperReports with Spring
## Establish the deployed contract
Confirm the JasperReports Library and extension versions, Java version, Spring Framework and Spring Boot versions, supported output formats, template packaging, data source, authentication requirements, and response/error contract. Check dependency convergence and test the exact versions deployed; Spring Boot and JasperReports compatibility should not be inferred from unrelated sample applications. This skill covers JasperReports Library integrations, not JasperReports Server or JasperReports IO.
## Resolve reports through trusted identifiers
Map a small, explicit set of caller-visible report IDs to known classpath resources or application-owned report definitions. Reject unknown IDs before compiling or filling. Never turn a request parameter into a filesystem path, classpath resource name, URL, JRXML source, class name, or query fragment. Validate report parameters and apply authorization to the report and its data before running it. Use [hardening](../hardening/SKILL.md) when templates, query inputs, or resource locations can cross a trust boundary.
Package fixed JRXML and required assets with the application and resolve them as classpath resources. Compile fixed designs at build time or application startup where practical, and fail startup clearly if a required resource cannot be loaded or compiled. Do not rely on an IDE or source-tree path. If compiled `JasperReport` instances are cached, use a bounded cache with an application-controlled key that includes template identity and revision. Share only compiled design objects: create fresh parameters, data sources or connections, `JasperPrint` objects, exporters, and output destinations per request. Follow [java-integration](../java-integration/SKILL.md) for cache, concurrency, and resource lifecycle details, and [data-sources](../data-sources/SKILL.md) for connection and cursor ownership.
## Build the HTTP boundary
Keep report resolution and rendering in an application service; keep the controller responsible for HTTP input and response mapping. For successful binary output, set the exact media type (for example `application/pdf`) and a safe `Content-Disposition` filename derived from the fixed report definition, not untrusted input. Validate or encode any user-influenced filename. Add `Content-Length` only when it is known and correct.
Complete rendering successfully before committing a response. For modest reports, buffer the completed output before returning it. For large reports, export to a request-scoped temporary destination and expose it only after successful completion; remove the temporary output on success and failure. Do not write directly to the servlet response while a report can still fail, because an already-committed partial body cannot be replaced with a useful error response. Close only streams the application opened, and never share an exporter or output stream between requests.
Bound request size, page count, execution time, and concurrent work according to the service's capacity. Apply authentication and authorization before data access. For asynchronous work, cancellation, or streaming, verify the exact JasperReports exporter behavior and ensure cancelled or failed partial output is discarded.
## Map failures deliberately
Return `404 Not Found` for an unknown report ID and use the application's documented status contract for invalid input, authorization failures, and unavailable data. Map rendering failures to a stable, generic server error response; do not expose stack traces, SQL, file paths, template source, or exception messages to callers. Log the original exception with an appropriate request correlation value, without logging credentials or report data. Catch expected failures at the boundary and preserve their causes; do not broadly catch exceptions or turn failures into empty success responses.
## Verify the deployed integration
Test the endpoint in a Spring application context using the same dependency versions and a packaged-resource setup representative of deployment. Verify successful status, bytes that can be parsed as the requested format, media type, safe filename, and any length headers. Verify unknown IDs, missing resources, invalid parameters, render/export failures, generic error bodies, cleanup of temporary output, and absence of partial success responses. Exercise concurrent requests with independent data and parameters when the service supports concurrency. A test against `target/classes` alone does not establish that resources work from the built JAR.
The report-smoke fixture for this skill uses JasperReports Library 7.1.1, Java 17, Spring Boot 3.5.7, and Spring Framework 6.2.19. Treat those as tested fixture versions, not a universal compatibility guarantee. Re-run the checks against the application's exact dependency graph and deployment artifact.
## Deliver
Report the tested JasperReports, extension, Java, Spring Framework, Spring Boot, and build versions; report-ID and resource strategy; request data and stream ownership; response headers and error mapping; exact validation commands and results; and untested deployment assumptions. Distinguish runtime-tested behavior from recommendations.
## Sources
<!-- ‹guest · 2026-11-29› -->
- [Spring Boot reference](https://docs.spring.io/spring-boot/reference/)
- [Spring Framework MVC reference](https://docs.spring.io/spring-framework/reference/web/webmvc.html)
- [JasperReports API](https://jasperreports.sourceforge.net/api/index.html)
- [Java integration](../java-integration/SKILL.md)
- [Hardening](../hardening/SKILL.md)
- [Data sources](../data-sources/SKILL.md)
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.