r/SpringBoot • • 10h ago

Discussion ApplicationReadyEvent starts consuming before the server is actually ready

5 Upvotes

I ran into a subtle timing issue recently: a @EventListener(ApplicationReadyEvent.class) bean that starts consuming from a message queue. The event fires, the consumer begins pulling messages, but the embedded Tomcat/Jetty server hasn't finished binding its ports yet. If a producer sends a reply or a dependent service calls back immediately, the connection is refused or the message lands in a dead-letter queue because the app isn't actually serving traffic yet.

The docs say ApplicationReadyEvent means the application context is fully refreshed and ready to use, but in practice "ready" doesn't always equal "listening on the connector port." I worked around it by injecting a WebServer and checking isStarted() before starting the consumer, but that feels brittle across different embedded servers.

public class QueueConsumer {

    private final WebServer webServer;

    u/EventListener(ApplicationReadyEvent.class)
    public void start() {
        if (!webServer.isStarted()) {
            // wait or defer — but how long? polling feels wrong
        }
        // start consuming
    }
}

Questions:

  1. Is there a cleaner Spring-native hook that guarantees the web server is actually accepting connections before I start consuming?
  2. Have others seen this in production, or is it mostly a local-dev timing issue?
  3. Should the consumer lifecycle be tied to the WebServer instead of the application context?

I haven't tested this across Tomcat, Jetty, and Undertow yet, so I can't confirm whether the behavior differs by server. If someone has a reproducible example, I'd like to see it.


r/SpringBoot • • 1h ago

News Spring AI was using Redis cache for sharing the responses among different users (CVE-2026-59417)

1 Upvotes

If you are using Spring AI's semantic cache (Redis) check this one.

You can reuse the earlier cached answer in the later similar question (the private data will be there as well).

Entries made by the advisor are kept forever in Redis unless you delete them.

The CVSS rating is 9.1, highest level under 10.

Fixed versions and the advisory details are in the write-up: https://hol.org/blog/cve-2026-59417-spring-ai-redis-semantic-cache


r/SpringBoot • • 21h ago

Question Are Springboot Udemy courses worth it?

1 Upvotes

Recently I have wanting to learn spingboot, the content I find on YouTube is quite fast paced and not structured so I'm looking for paid structured courses for learning.

Are they worth it?


r/SpringBoot • • 23h ago

Discussion Client-side DPoP with Spring Security, adding the proofs yourself and working around a WebFlux token type bug

1 Upvotes

I maintain authzen-enforcer, an open source Java SDK that enforces authorization decisions of a Policy Decision Point (PDP) through the OpenID AuthZEN API, with a Spring Boot starter. The application calls the PDP with its own token, obtained through the client credentials grant of Spring Security's OAuth 2.0 client. For the latest release I wanted that token to be DPoP-bound (RFC 9449), so that a stolen token alone cannot ask the PDP anything. Spring Security covers DPoP on the resource server side; on the client side the application does part of the work, so here is what I added.

What Spring Security offers (checked with 7.2.0, the version in Spring Boot 4.2.0)

  • DPoP on the resource server side: DPoPAuthenticationProvider, proof decoding and validation, and a replay validator.
  • The servlet token response converter reads token_type: DPoP.
  • Creating proofs is not part of spring-security-oauth2-client (there is no DPoP class in it as of 7.2.0), so the application adds them to its token requests itself. Without a proof, the authorization server issues a plain bearer token.

What I had to add

  1. A proof on every token request. On the servlet side, this is a ClientHttpRequestInterceptor on the RestClient of the token response client. The proof takes htm and htu from the outgoing request, has no ath because there is no token yet, and is new for every request:
  2. If the authorization server answers 400 with error="use_dpop_nonce", the request is repeated once with the nonce of its DPoP-Nonce header. On WebFlux, the same thing is an ExchangeFilterFunction on the WebClient.
  3. Reading the token type on WebFlux. The reactive OAuth2AccessTokenResponseBodyExtractor maps only Bearer, so a token_type: DPoP response fails with "tokenType cannot be null". The starter reads the token response itself for now. I reported this as spring-security#20189.
  4. No silent downgrade. If the request carried a proof but the response says Bearer, the starter fails the request instead of sending an unbound token in place of a bound one.
  5. Requests to the PDP. Each one carries Authorization: DPoP <token> and a new proof with ath, and retries get a new proof too, since a server is expected to refuse a proof it has already seen.
  6. An application's own OAuth2AccessTokenResponseClient bean would bypass all of this, so with DPoP on the starter refuses to start next to one instead of quietly sending token requests without proofs.

Checking it against a real server

The examples repository runs the Spring MVC and WebFlux applications with DPOP=1 against Keycloak 26.8.2, which is both the authorization server and the PDP there. Keycloak binds the token when the token request carries a proof, with no client setting. Besides the application's own requests, the decision check asks the PDP directly with a token bound to the same key:

DPoP the type of the PEP's token, requested with a proof
200 the PDP answers the token with a proof of its key
401 the PDP refuses the same proof again (a replay)
401 the PDP refuses a proof of another key (a stolen token)
401 the PDP refuses a proof for another endpoint
401 the PDP refuses the token without a proof
401 the PDP refuses the token as a bearer token

The replay refusal comes from Keycloak itself, because its AuthZEN endpoints run inside Keycloak. A PDP or resource server elsewhere has to remember the jti values of the proofs it accepts on its own.

Questions

  • Is anyone doing client-side DPoP with Spring Security in another way, for example with the authorization code flow, where the same idea applies to more requests?
  • Would first-class proof creation in spring-security-oauth2-client be useful to you? The closest open request I found is #18228, which asks for a way to mark a client registration as requiring DPoP.