3

So, I was reading online and you cannot make Configuration final because CGLIB extends the class to create a proxy. However, I was reading the documentation for @Scope, and the default proxyMethod value is that no proxy is created (link here- https://docs.spring.io/springframework/docs/current/javadoc-api/org/springframework/context/annotation/Scope.html).

So, my main question is, is a proxy created for each @Configuration?

  • scoping and proxying are totally different things. When needed for a scope a proxy is created for a scope but not for a singleton or application scoped bean. Even a singleton might be proxied based on other Aspects (like transactions, retrying etc.). An `@Configuration` class **might** be proxied depended on the `proxyBeanMethods` attribute (which defaults to `true`). – M. Deinum May 23 '20 at 08:35

1 Answers1

6

Spring creates proxy for a bean only if required ( example:Transaction management). I have explained this for another SO question here , please go through A2 section of the answer for more details.

For a @Configuration annotated class a proxy will always be created , which implies that it is required. Why it is required can be understood from the following references.

@Bean : Read through sections @Bean Methods in @Configuration Classes and @Bean Lite Mode

Do read through this excellent answer from @kriegaex to understand the inner workings of @Configuration class.

So to answer your question is a proxy created for each @Configuration ? Yes , unless the proxyBeanMethods for @Configuration is configured explicity.

Hope this helps.

R.G
  • 6,436
  • 3
  • 19
  • 28