I hit the problem described in https://github.com/spring-projects/spring-framework/issues/27971.
Rather than just adding the <argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
to my Surefire configuration, I decided to upgrade to Spring-Boot 2.6.4 (from 2.6.3) to take the fix that was described (because Spring-Boot 2.6.4 uses Spring framework version 5.3.16).
However, this led me to a different error, whereby we hit a org.springframework.beans.factory.BeanNotOfRequiredTypeException
for the lambda bean, specifically:
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'defaultMyThing' is expected to be of type 'com.oliverlockwood.MyThing' but was actually of type 'jdk.proxy2.$Proxy142'
At present, my not-so-pleasant options seem to come down to:
- Run under Java 17, using --add-opens
JVM argument, and get stuck on Spring Boot 2.6.3 (not great)
- Run under Java 11 (not great), but be able to upgrade to Spring Boot 2.6.4
- Run under Java 17 and Spring Boot 2.6.4, but change the lambda beans to be explicit (not great).
I couldn't see a ticket representing this issue, and as Spring-Boot 2.6.4's only recently been released it is plausible that I might be the first person to hit this.
Comment From: sbrannen
Hi @oliverlockwood,
Thanks for raising the issue. It may be a regression.
To help use analyze this, can you please provide a minimal sample application (or test class) that reproduces the BeanNotOfRequiredTypeException
you are encountering (preferably as a Git repository that we can check out or a ZIP file that we can download and run)?
Comment From: oliverlockwood
Yes @sbrannen.
I have created repo https://github.com/oliverlockwood/spring-framework-issue-28209 which demonstrates this clearly.
It turns out that the error case requires an AOP annotation to be applied to the interface being implemented (in this case, I've used @Retryable
).
Please let me know if you need any further information, but I think it should now be pretty clear.
Comment From: sbrannen
Thanks for creating the repo, @oliverlockwood. Much appreciated.
We'll look into it.
Comment From: sbrannen
It turns out that the error case requires an AOP annotation to be applied to the interface being implemented (in this case, I've used
@Retryable
).
It's not because of the use of an annotation. Rather, the AOP advice for @Retryable
makes use of an introduction (i.e., it introduces the org.springframework.retry.interceptor.Retryable
marker interface to the proxy), and the fix for #27971 does not take this into account.
That's why the diagnostics generated by Spring Boot include the following.
The bean is of type 'jdk.proxy2.$Proxy64' and implements:
org.springframework.retry.interceptor.Retryable
org.springframework.aop.SpringProxy
org.springframework.aop.framework.Advised
org.springframework.core.DecoratingProxy
Here we see that org.springframework.retry.interceptor.Retryable
is included in the set of interfaces implemented by the proxy, but the lambda interface (com.oliverlockwood.springframework.issue28209.ExampleInterface
) is not.
Comment From: sbrannen
This regression has been fixed in 6fad00ed222c48f9d845bcea9d5a50dcf7c2a169.
@oliverlockwood, I tested your example application locally with a patch containing the fix, but it would be great if you could verify the fix on your end using an upcoming 5.3.19 snapshot build and let us know that it works for your.