When to set proxyBeanMethods to false in Springs Configuration?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
In Spring, @Configuration(proxyBeanMethods = true) tells the container to create a CGLIB proxy around the configuration class so calls between @Bean methods still return managed singleton beans. Setting it to false disables that interception and treats each @Bean method like a plain factory method.
You should set it to false when the configuration class is "lite": its @Bean methods are independent and do not call one another to obtain managed beans. In that case, disabling proxies reduces indirection and makes startup a little simpler.
What the Proxy Does
With the default proxy behavior, Spring subclasses the configuration class. When one @Bean method calls another, the proxy intercepts the call and returns the bean from the application context rather than constructing a new instance directly.
That matters in code like this:
Because of the proxy, serviceB() inside serviceA() resolves to the managed bean, not to a fresh new ServiceB() each time.
When false Is the Right Choice
Set proxyBeanMethods = false when:
- each
@Beanmethod is self-contained - dependencies are injected through method parameters instead of direct method calls
- you do not rely on inter-bean calls inside the same configuration class
This style is common in modern Spring Boot auto-configuration and in application code that prefers explicit dependencies.
A safe pattern looks like this:
This version does not need proxy interception because Spring resolves ServiceB through the method parameter.
Why Many Teams Prefer false
Using false encourages a cleaner configuration style. Instead of one @Bean method reaching into another, each bean declares its dependencies explicitly.
Benefits include:
- fewer CGLIB proxies
- slightly simpler startup behavior
- configuration code that is easier to reason about
- fewer surprises when reading or testing configuration classes
The performance gain is usually modest, so clarity is the main reason to prefer it.
When You Should Keep It true
Keep proxyBeanMethods = true if one @Bean method directly calls another and you expect those calls to respect container semantics.
If you turn it off in that situation, you can accidentally create extra instances:
Here serviceB() inside serviceA() is just an ordinary Java method call. It does not go through the container, so ServiceA may receive a different instance than the managed bean.
A Practical Rule
If your configuration follows constructor-like dependency style through method parameters, use false. If it relies on configuration-method self-invocation, keep true or refactor.
That rule is simple and prevents most mistakes.
Common Pitfalls
- Turning it off without checking for direct
@Beanmethod calls inside the same class. - Assuming
falsechanges bean scope rules by itself. It changes method interception, not bean scope semantics. - Using self-invocation patterns that make configuration behavior harder to reason about.
- Expecting a major performance win when the real benefit is mostly code clarity.
- Mixing lite configuration style with proxy-dependent configuration style in the same class.
Summary
- '
proxyBeanMethods = truepreserves container semantics for inter-bean method calls.' - '
proxyBeanMethods = falseis best when@Beanmethods are independent.' - Prefer
falsewhen dependencies are passed as method parameters. - Keep
trueif one@Beanmethod directly calls another and expects the managed bean. - The main benefit of
falseis simpler, clearer configuration code.
Related reading
- When to use a certain Reinforcement Learning algorithm?
- When to use a SortedListTKey, TValue over a SortedDictionaryTKey, TValue?
- When to use enumerateObjectsUsingBlock vs. for
- When to use MyISAM and InnoDB?
- When to use AtomicReference in Java?
- When to use ConcurrentKafkaListenerContainerFactory?
- When to use PNG or JPG in iPhone development?
- When to use pointers in C/.NET?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.