Skip to content

Commit efc3cad

Browse files
committed
Fixed Circular Bean References in Java Config
Fixes spring-projectsgh-4489
1 parent 01579be commit efc3cad

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void setFilterChainProxySecurityConfigurer(
160160
}
161161

162162
@Bean
163-
public AutowiredWebSecurityConfigurersIgnoreParents autowiredWebSecurityConfigurersIgnoreParents(
163+
public static AutowiredWebSecurityConfigurersIgnoreParents autowiredWebSecurityConfigurersIgnoreParents(
164164
ConfigurableListableBeanFactory beanFactory) {
165165
return new AutowiredWebSecurityConfigurersIgnoreParents(beanFactory);
166166
}

config/src/test/groovy/org/springframework/security/config/annotation/BaseSpringSpec.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
5151
* @author Rob Winch
5252
*/
5353
abstract class BaseSpringSpec extends Specification {
54+
boolean allowCircularReferences = false
5455
@AutoCleanup
5556
ConfigurableApplicationContext context
5657
@AutoCleanup
@@ -89,6 +90,7 @@ abstract class BaseSpringSpec extends Specification {
8990

9091
def loadConfig(Class<?>... configs) {
9192
context = new AnnotationConfigWebApplicationContext()
93+
context.setAllowCircularReferences(allowCircularReferences)
9294
context.register(configs)
9395
context.setServletContext(new MockServletContext())
9496
context.refresh()
@@ -169,4 +171,4 @@ abstract class BaseSpringSpec extends Specification {
169171
def getObjectPostProcessor() {
170172
oppContext.getBean(ObjectPostProcessor)
171173
}
172-
}
174+
}

config/src/test/groovy/org/springframework/security/config/annotation/web/WebSecurityConfigurerAdapterTests.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class WebSecurityConfigurerAdapterTests extends BaseSpringSpec {
176176
static ContentNegotiationStrategy CNS
177177

178178
@Bean
179-
public ContentNegotiationStrategy cns() {
179+
public static ContentNegotiationStrategy cns() {
180180
return CNS
181181
}
182182
}
@@ -193,6 +193,7 @@ class WebSecurityConfigurerAdapterTests extends BaseSpringSpec {
193193

194194
def "UserDetailsService lazy"() {
195195
setup:
196+
allowCircularReferences = true
196197
loadConfig(RequiresUserDetailsServiceConfig,UserDetailsServiceConfig)
197198
when:
198199
findFilter(MyFilter).userDetailsService.loadUserByUsername("user")
@@ -274,7 +275,7 @@ class WebSecurityConfigurerAdapterTests extends BaseSpringSpec {
274275
static AuthenticationTrustResolver TR
275276

276277
@Bean
277-
public AuthenticationTrustResolver tr() {
278+
public static AuthenticationTrustResolver tr() {
278279
return TR
279280
}
280281
}

config/src/test/groovy/org/springframework/security/config/annotation/web/configurers/ExceptionHandlingConfigurerTests.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class ExceptionHandlingConfigurerTests extends BaseSpringSpec {
155155
static ContentNegotiationStrategy CNS
156156

157157
@Bean
158-
public ContentNegotiationStrategy cns() {
158+
public static ContentNegotiationStrategy cns() {
159159
return CNS
160160
}
161161
}

0 commit comments

Comments
 (0)