Ce contenu n’est pas encore disponible dans votre langue.
This article describes how the Java apps in your Aspire solution connect to other resources, in both directions. When another resource references a Java app, Aspire injects the Java app’s URL into that resource, so apps written in C#, Go, Python, TypeScript, or Java can call it without hard-coded addresses. When a Java app references other resources — such as a database, a cache, or another service — Aspire injects their URLs and connection details into the JVM as environment variables, which Spring Boot, Quarkus, and plain Java apps read through their standard configuration mechanisms. It also describes how Java apps send telemetry to the Aspire dashboard and trust the development certificate.
The examples in this article use the following AppHost. The orders Spring Boot app references a PostgreSQL database and the catalog Spring Boot app, and a Node.js storefront app references orders:
WithReferencewithReference injects the referenced resource’s connection information into the referencing resource, and WaitForwaitFor delays the referencing resource until the referenced one is running — or healthy, when it has a health check. A Java app can be on either side of a reference, and the environment variables are the same whatever language the other app uses.
Aspire passes connection information to apps as environment variables. A Java app is on both sides of that exchange: it exposes endpoints that other apps call, and it receives variables of its own.
When a resource references a Java app, Aspire injects the URL of each of the Java app’s endpoints. In the preceding AppHost, storefront receives the following variables for the orders app:
Environment variable
Description
ORDERS_HTTP
The URL of the orders app’s http endpoint, named {RESOURCE}_{ENDPOINT}. Read this variable from apps that don’t use .NET service discovery.
AddSpringBootApp and AddQuarkusApp name their endpoint http. When you add an endpoint with a different name to a Java app, the variables use that name instead — for example, an endpoint named admin produces ORDERS_ADMIN. For the naming rules, see Endpoint URLs and Service discovery variables.
A Java app receives the variables of every resource that it references. In the preceding AppHost, orders receives CATALOG_HTTP and services__catalog__http__0 for the catalog app, and the connection properties of the ordersdb database, which include:
Environment variable
Description
ORDERSDB_JDBCCONNECTIONSTRING
The JDBC URL, in the format jdbc:postgresql://{Host}:{Port}/{DatabaseName}. It doesn’t include the credentials.
Apps call a Java app at the URL that Aspire injects. Each example calls the orders app from the storefront app in the preceding AppHost. Only the language differs.
The https+http scheme prefers an HTTPS endpoint and falls back to HTTP. Without service discovery, read the URL from the ORDERS_HTTP configuration value instead.
There’s no Aspire client package for Java. A Java app reads the variables that Aspire injects through its framework’s standard configuration mechanism. Each example configures the orders app from the preceding AppHost to call the catalog app and to use the ordersdb database. Only the framework differs.
A default after the colon in a placeholder, such as http://localhost:8080 for CATALOG_HTTP, keeps the app runnable outside Aspire. Placeholders without a default make the app fail to start when the variable isn’t set.
Every Java resource receives the standard OpenTelemetry environment variables, but a JVM doesn’t export telemetry by itself. Use one of the following:
The OpenTelemetry Java agent. The agent reads the OTEL_* variables directly and instruments common libraries and frameworks without code changes. To attach it, see Attach the OpenTelemetry Java agent.
The Quarkus OpenTelemetry extension. When you run the AppHost, a Quarkus app added with AddQuarkusApp receives copies of the settings under the QUARKUS_OTEL_* names that the extension reads. A published app needs a mapping in application.properties, as described in Add a Quarkus app.
An app that uses neither doesn’t send telemetry to the dashboard, but its console output still appears in the dashboard’s console logs.
Aspire points each Java resource’s JVM at a trust store that contains the development certificate and the system’s root certificates, through JAVA_TOOL_OPTIONS. HTTP clients and database drivers that use the JVM’s default trust settings, such as java.net.http.HttpClient, therefore trust HTTPS endpoints that use the development certificate without any code changes. Code that builds its own SSLContext from a specific trust store doesn’t use Aspire’s trust store. For details, see Configure certificate trust.