New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regarding disabling AopAutoConfiguration when using @EnableAspectJAutoProxy #27375
Comments
I think if you want to use AOP, you just need to import spring-boot-starter-aop dependency。If you want to used JDK Dynamic proxy,add the properties spring.aop.proxy-target-class: true and not need to use @EnableAspectJAutoProxy。 The following reasons: if you not add the properties spring.aop.auto: false,the annotation EnableAspectJAutoProxy of AopAutoConfiguration#CglibAutoProxyConfiguration class will cover the annotations(EnableAspectJAutoProxy) you define。 |
There are lots of different way that proxying is enabled, some of which are more of an implementation detail than something that the user is really aware of. The fact that the auto-configuration can't easily back off is why we have the |
FWIW, using The only thing in Spring Boot which really helped me to activate JDK proxy mode, was
Can you at least log a clear warning that some user configuration is in the process of being ignored? |
Unfortunately not. As I said above we can't tell if the configuration is a side-effect of something else or a specific intent being declared by the user. That means that we can’t accurately determine when a warning should be logged just as we can’t determine if the auto-configuration should back off. |
I dare to disagree, even though I do not know how exactly Spring determines its configuration. But it should be possible to generically determine if the same configuration annotation or equivalent configuration key is used multiple times with conflicting parameter values. In that case, a warning could be logged, exactly naming the keys, values, sources (config file, config class). It could also log the effective configuration in that case, so the user knows which one "won". Logging this information would been be useful even when there is no conflict. Of course, it could be made optional or depend on the log level. I think this should be done in Spring Core, but Boot could utilise it or indirectly profit from it, being the Spring project with the most behind the scenes config "magic". I am actually surprised that this mechanism does not exist yet, because for a framework that complex it is unnatural not to have it. Complex tools need adequate diagnostics. |
As I said before, we have no way of determining if configuration is an intentional override or if there is an accidental conflict. Let’s take configuration properties as an example. It is quite common to configure a property in one application.properties file and then override it in another profile-specific file. We could push this information out via logging but for many cases it would be irrelevant. For cases where a user feels it is relevant, the information can be pulled from the Actuator’s env endpoint. Proxy configuration is similar. We cannot infer the user’s intent and logging everything would be irrelevant noise in many cases. As such, I don’t think logging would provide useful diagnostics. Unlike configuration properties, there’s nowhere to pull this information from if a user wishes to do so. If you’d like to see an improvement in this area, please open a Spring Framework issue. It may be possible for them to track all the sources of proxy configuration and make that information available somehow. |
Like I said:
|
While testing Spring proxy, an incomprehensible problem appeared.
To test JDK Dynamic proxy, we used @EnableAspectJAutoProxy's proxyTargetClass as false, but we still used CGLIB.
When I looked up the data, I found out that the following properties should be added to the application.yml for normal operation.
I used @EnableAspectJAutoProxy, but I think it should be disabled when using @EnableAspectJAutoProxy because it can be confusing to manually turn off auto settings.
The text was updated successfully, but these errors were encountered: