question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clarify configuration lite support and offer an opt-in option

See original GitHub issue

The Spring Boot team has been investigating startup time improvements by not relying on the proxy capabilities of configuration classes. Turns out that not using that stuff (basically switching all auto-configurations and related imports to “lite mode”) makes quite a difference https://github.com/spring-projects/spring-boot/issues/9068#issuecomment-461520814

I am not a big fan that we were looking for @Bean methods in any component, treating them in lite mode if they don’t have the @Configuration stereotype. I was wondering if we would be open to revisit this in the 5.2 line.

Being able to opt-out from the proxy mode using the @Configuration stereotype would be ideal. We are not keen to remove @Configuration and use the lite mode as it stands as:

  • That’s not representative of what a good citizen of the framework should do (using the right stereotype)
  • We have an annotation processor that identifies configuration classes to extract conditions so that we can back off (without loading the ASM metadata or the class) when a static condition does not match (i.e. class not on the classpath)

Having a way to opt-out would be also a nice opportunity to clarify the behaviour and stop scanning components for bean factory methods.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
jhoellercommented, Mar 8, 2019

I have an implementation ready to be committed now, using a proxyBeanMethods flag as suggested above. (Even if this is technically not “proxying” in the AOP sense but rather method interception through overriding in the same instance, I suppose it can still be called proxying in a general sense.)

Whatever we may feel about it, I can’t see how we’d limit @Bean methods to @Configuration classes at this point… without breaking plenty of people who intentionally or unintentionally don’t use the @Configuration stereotype for some of their @Bean-declaring classes. This has been out there for 10 years and I am not inclined to break this, even if it is now possible to effectively get the same behavior using a new flag on @Configuration… Arguably the very fact that this is now a well-defined mode of regular configuration classes makes it easier to understand that the same behavior is applicable to individual @Bean methods outside of configuration classes as well, with less surprise that there is no method interception through CGLIB subclasses there, and that this is a proper variant of operation.

As for the annotation detection overhead, let’s tackle this along with our other issues for it. Once we have a method-level indication in the components index, we’ll get efficient skipping not only for @Bean checks but also for @EventListener, @Scheduled, @Transactional, the caching annotations etc. And if we introduce corresponding programmatic hints at the bean definition level, those should be equally applicable to the detection of all those method-level annotations so that we never reflectively iterate the methods of the affected component classes - not for @Bean detection and not for AOP proxying either.

1reaction
sbrannencommented, Mar 5, 2019

While discussing this with @wilkinsona, I proposed we name the boolean flag in @Configuration something like proxyMethodInvocations = false analogous to proxyTargetClass in other places.

He came back with “proxyBeanMethodInvocations or perhaps proxyBeanMethods to make it clear that it’s only @Bean methods that are affected.”

I tend to like @Configuration(proxyBeanMethods = false) to turn off the default behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Opt In vs Opt Out: What's the Difference? | Termly
Opting in means that a user will take an affirmative action to offer their consent. The most common way businesses implement opt-in methods...
Read more >
How To Create GDPR-Compliant Sign-Up Forms (+ Examples)
A complete guide to creating GDPR-compliant opt-in forms that generate subscribers. Includes tips and examples. Learn all the best practices now!
Read more >
Get support in Microsoft Endpoint Manager admin center
In this article, we explain how to get to Help and support and review your different support options from within the admin center....
Read more >
The 15 Best Android Developer Options Worth Tweaking
Android phone in hand showing Developer options. Android has lots of tweaks available in its main Settings app, as well as the options...
Read more >
Basic Privacy Settings & Tools | Facebook Help Center
After you've shared a post, you have the option to change who it's shared with. ... Lists give you a way to share...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found