I've seen the following definition in the code:
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
@Component
public class SomeComponent {
<...>
}
This is a singleton scoped bean. And it seems for me, that there is no reason to proxy it. As far as I understand we should to proxy a bean in case if its scope isn't singleton and differs from a scope of another bean, into which we are going to inject it.
Probably I don't know something. What may be a reason to proxy a singleton?
After an investigation I found an answer for my question in an outdated Spring's documentation:
It answers my question, because
<aop:scoped-proxy/>
is an alternative for@Scope
annotation. But current documentation differs from the old one:It means, now you will not see
BeanCreationException
in case if you will try to define a singleton scoped proxy. But anyway, I don't fully understand the purpose of this vague use-case. So, if anyone understands what this statement means, please, clarify it in comments.Conclusion: In the most cases there is no reason to proxy a singleton scoped bean.