-
Notifications
You must be signed in to change notification settings - Fork 38k
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
Spring AOP cannot generate proxy for lambda on Java 16+ #27971
Comments
You can make the code work the way you'd expect by adding the following to your <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
</configuration>
</plugin> But this is certainly an interesting issue. I'm guessing that the JDK thinks that the |
For the sake of clarity, after investigating this issue, there does not appear to be an issue with the JDK. Rather:
Note that For the time being, people can use the However, the Spring team will investigate a way to avoid the creation of CGLIB-based proxies for lambda expressions. A JDK dynamic proxy should always suffice for a class that can only ever be used via the functional interface it implements. Dynamic proxies should also be used for lambda expressions and method references even if |
Available WorkaroundsThe easiest way to work around this issue when using Spring Boot is by adding the following to your spring.aop.proxy-target-class=false If you're using Spring Framework without Spring Boot, ensure that If you do not wish to make either of the above changes to your application configuration, you can run your application (or tests) using |
@Ferioney, I confirmed that the change submitted in 5d7a632 allows your sample application to pass without any changes. Please add the following to your <properties>
<java.version>17</java.version>
<spring-framework.version>5.3.16-SNAPSHOT</spring-framework.version>
</properties>
<!-- ... -->
<repositories>
<repository>
<id>repository.spring.snapshot</id>
<name>Spring Snapshot Repository</name>
<url>https://repo.spring.io/snapshot</url>
</repository>
</repositories>
|
@sbrannen checked and it worked as expected. |
I'm migrating to Java 17 and found an issue with proxy generation for 'lambda beans'.
Spring AOP cannot generate a proxy for beans like:
Errors:
But if I use class implementation it works fine:
I prepared demo project aop-issue to show the issue:
The text was updated successfully, but these errors were encountered: