When implementing multi-issuer JWT authentication in Spring Security (Spring Boot 3.x), the application failed to start with the following error:
Found 2 beans for type interface org.springframework.security.authentication.AuthenticationManager,
but none marked as primary
AuthenticationManager
bean in the application context.AuthenticationManager
into HttpSecurityConfiguration
.AuthenticationManager
exist (without @Primary
), Spring cannot decide which one to use β startup fails.adminAuthenticationManager
registeredAuthenticationManager
@Bean AuthenticationManager
, so Spring registered them globally.HttpSecurity
initialization β crash.AuthenticationManager
.JwtIssuerAuthenticationManagerResolver
.AuthenticationManager
s inside the resolver