Setting Up & Configuration
Setting up dependencies and application properties.
Dependency
Add library as dependency to Maven or Gradle. See the actual versions on Maven Central. Add it along with repository in your dependency manager. Java 17 or higher is required to use this library.
| Problem4J Spring Version | About |
|---|---|
3.x (latest - 3.0.0) | Spring Boot 4.x, problem4j-core-2.x |
2.x (latest - 2.2.4) | Spring Boot 4.x, problem4j-core-1.x |
1.x (latest - 1.2.9) | Spring Boot 3.x, problem4j-core-1.x |
Use version from the above table while managing your dependency or visit Maven Central to find out latest version in given generation.
<dependencies>
<!-- pick the one for your project -->
<dependency>
<groupId>io.github.problem4j</groupId>
<artifactId>problem4j-spring-webflux</artifactId>
<version>{version}</version>
</dependency>
<dependency>
<groupId>io.github.problem4j</groupId>
<artifactId>problem4j-spring-webmvc</artifactId>
<version>{version}</version>
</dependency>
</dependencies>
dependencies {
// pick the one for your project
implementation("io.github.problem4j:problem4j-spring-webflux:{version}")
implementation("io.github.problem4j:problem4j-spring-webmvc:{version}")
}
Note: To limit the number of transitive dependencies, you need to include Spring Boot explicitly in your project.
Configuration
Library can be configured with following properties.
problem4j.enabled
Property that enables or disables all auto-configurations provided by this module. Defaults to true (enabled).
problem4j.detail-format
Property that specifies how exception handling imported with this module should print the "detail" field of the
Problem model (lowercase, capitalized - default, uppercase). Useful for keeping a consistent style between
errors generated by the library and those from your application.
problem4j.tracing-source
Property that decides where the trace identifier, stored in the request context (ProblemContext) under the traceId
key, comes from (auto - default, simple, micrometer). simple takes it from the header configured with
problem4j.tracing-header-name, or generates a random one. micrometer takes it (and spanId) from the current
Micrometer Tracing span, so it matches the one in logs, and fails application startup if
io.micrometer:micrometer-tracing is not on the classpath (unless a custom ProblemContext filter bean is defined).
auto uses micrometer if it's on the classpath, and simple otherwise.
See Tracing chapter for more info.
problem4j.tracing-header-name
Property that specifies the name of the HTTP header used for tracing requests. If set, the trace identifier from this
header is extracted and stored in the request context (ProblemContext) under the traceId key, and written into the
response header with the same name. With micrometer tracing source, the header value is used only if no tracing span
is available, but the response header is still written (with the trace identifier of the span). This value can be
referenced in override templates using the {context.traceId} placeholder. Defaults to null (disabled).
See Tracing chapter for more info.
problem4j.type-override
Defines a template for overriding the "type" field of Problem responses. Useful for mapping logical problem
identifiers to environment-specific URIs (for example, production vs. staging). Defaults to null (disabled).
See Problem Post-Processor chapter for more info.
problem4j.title-override
Defines a template for overriding the "title" field of Problem responses. Useful for applying a consistent title
format across all problems or injecting runtime context into the title. Defaults to null (disabled).
See Problem Post-Processor chapter for more info.
problem4j.instance-override
Defines a template for overriding the "instance" field of Problem responses. Useful for appending runtime context
such as request trace identifiers or constructing predictable instance URIs. Defaults to null (disabled).
See Problem Post-Processor chapter for more info.
problem4j.extension-overrides.<name>
Defines templates for overriding extension members of Problem responses, keyed by extension name. Useful for adding
runtime context, such as request trace identifiers, as separate fields of every response. An override replaces an
extension with the same name set by an exception or resolver. Names containing dots or other special characters must use
bracket notation (problem4j.extension-overrides[app.version]=1.0). Extension names keep their case only if set in
.properties / .yaml files (or other sources with the same format, like SPRING_APPLICATION_JSON). Defaults to
empty (disabled).
See Problem Post-Processor chapter for more info, including setting overrides in YAML files and environment variables.
problem4j.observation-errors
Decides which exceptions handled by Problem4J are recorded as errors of the current HTTP server observation
(server - default, all, none). With server, exceptions resulting in a 5xx response are recorded. With
all, every handled exception is recorded, regardless of the response status. With none, nothing is recorded, as in
versions prior to 3.1.0.
See Observation Errors chapter for more info.
problem4j.duplicate-resolver-policy
Decides what happens when several ProblemResolver beans handle the same exception class with equal precedence
(fail - default, first, last). With fail, application startup fails with an IllegalStateException naming
the conflicting beans. With first, the first one registered in the application context is used. With last, the last
one registered in the application context is used. As auto-configured resolvers are registered after application-defined
ones, last makes a built-in resolver win over your own one with equal precedence, similarly to versions prior to
3.1.0.
See Implementing ProblemResolver chapter for more info on
resolver precedence.
problem4j.resolver-caching.enabled
Enables caching of resolved ProblemResolver instances to avoid repeated reflection and lookup. Defaults to false
(disabled). When disabled, every resolution performs a fresh lookup. Enable if you have many repeated resolutions of a
stable set of exception / resolver types.
See Resolver Caching chapter for more info.