Spring / Spring7 Intermediate to Advanced Interview questions
How is the API version resolved when a client sends no version header in Spring Framework 7?
The outcome depends on how the application configured its ApiVersionStrategy. If a default version is set via ApiVersionConfigurer.setDefaultVersion(...), an unversioned request is treated as if it had requested that default, and gets routed accordingly - this is the common choice for keeping older, pre-versioning clients working unchanged after versioning is introduced.
@Configuration public class WebConfig implements WebMvcConfigurer { @Override public void configureApiVersioning(ApiVersionConfigurer configurer) { configurer.useRequestHeader("API-Version").setDefaultVersion("1"); } }
If no default is configured and a mapping explicitly requires a version, Spring rejects the request with a client error rather than guessing which handler was intended. If an unversioned handler method also exists alongside versioned ones for the same path, that unversioned method typically acts as a catch-all for requests carrying no version at all. Spring's baseline-version syntax (version = "1.2+") adds further nuance: a handler declared this way matches any request version at or above 1.2, so as new minor versions are introduced, older baseline-declared handlers keep serving them without needing a new mapping for every increment.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
