Fixed Circular Bean References in Java Config

Fixes gh-4489
This commit is contained in:
Rob Winch 2017-08-09 16:24:01 -05:00
parent 01579be7d4
commit efc3cadd43
4 changed files with 8 additions and 5 deletions

View File

@ -160,7 +160,7 @@ public class WebSecurityConfiguration implements ImportAware, BeanClassLoaderAwa
}
@Bean
public AutowiredWebSecurityConfigurersIgnoreParents autowiredWebSecurityConfigurersIgnoreParents(
public static AutowiredWebSecurityConfigurersIgnoreParents autowiredWebSecurityConfigurersIgnoreParents(
ConfigurableListableBeanFactory beanFactory) {
return new AutowiredWebSecurityConfigurersIgnoreParents(beanFactory);
}

View File

@ -51,6 +51,7 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
* @author Rob Winch
*/
abstract class BaseSpringSpec extends Specification {
boolean allowCircularReferences = false
@AutoCleanup
ConfigurableApplicationContext context
@AutoCleanup
@ -89,6 +90,7 @@ abstract class BaseSpringSpec extends Specification {
def loadConfig(Class<?>... configs) {
context = new AnnotationConfigWebApplicationContext()
context.setAllowCircularReferences(allowCircularReferences)
context.register(configs)
context.setServletContext(new MockServletContext())
context.refresh()
@ -169,4 +171,4 @@ abstract class BaseSpringSpec extends Specification {
def getObjectPostProcessor() {
oppContext.getBean(ObjectPostProcessor)
}
}
}

View File

@ -176,7 +176,7 @@ class WebSecurityConfigurerAdapterTests extends BaseSpringSpec {
static ContentNegotiationStrategy CNS
@Bean
public ContentNegotiationStrategy cns() {
public static ContentNegotiationStrategy cns() {
return CNS
}
}
@ -193,6 +193,7 @@ class WebSecurityConfigurerAdapterTests extends BaseSpringSpec {
def "UserDetailsService lazy"() {
setup:
allowCircularReferences = true
loadConfig(RequiresUserDetailsServiceConfig,UserDetailsServiceConfig)
when:
findFilter(MyFilter).userDetailsService.loadUserByUsername("user")
@ -274,7 +275,7 @@ class WebSecurityConfigurerAdapterTests extends BaseSpringSpec {
static AuthenticationTrustResolver TR
@Bean
public AuthenticationTrustResolver tr() {
public static AuthenticationTrustResolver tr() {
return TR
}
}

View File

@ -155,7 +155,7 @@ class ExceptionHandlingConfigurerTests extends BaseSpringSpec {
static ContentNegotiationStrategy CNS
@Bean
public ContentNegotiationStrategy cns() {
public static ContentNegotiationStrategy cns() {
return CNS
}
}