#3912 lazyBean method respects @Primary annotation

This commit is contained in:
Karl Goffin
2018-10-31 22:04:06 -04:00
committed by Rob Winch
parent b2c2f84f00
commit db5e54266c
2 changed files with 49 additions and 11 deletions

View File

@@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.security.access.annotation.Secured;
@@ -506,4 +507,27 @@ public class AuthenticationConfigurationTests {
@Autowired
Service service;
}
@Test
public void getAuthenticationManagerBeanWhenMultipleDefinedAndOnePrimaryThenNoException() throws Exception {
this.spring.register(MultipleAuthenticationManagerBeanConfig.class).autowire();
this.spring.getContext().getBeanFactory().getBean(AuthenticationConfiguration.class).getAuthenticationManager();
}
@Configuration
@Import(AuthenticationConfiguration.class)
static class MultipleAuthenticationManagerBeanConfig {
@Bean
@Primary
public AuthenticationManager manager1() {
return mock(AuthenticationManager.class);
}
@Bean
public AuthenticationManager manager2() {
return mock(AuthenticationManager.class);
}
}
}