Skip to content
Advertisement

Spring is trying to subclass a record component when aop is present

I have a spring boot application in which I make use of aspects. Recently, I tried converting my @ConfigurationProperties classes to java records, but it fails with "Cannot subclass final class {..}Properties". It seems spring is trying to make cglib proxies for my records, which obviously fail. Is there any way to tell spring not to make proxies for specific classes?

Edit:

The properties:

JavaScript

Stacktrace:

JavaScript

Edit 2: A minimal, reproducible example: https://github.com/moxaj/aspect-mcve-2

Advertisement

Answer

I cloned your MCVE repository. Thanks, that was helpful.

Please note that Java records are implicitly final. Therefore, Spring AOP cannot subclass them in order to create dynamic proxies.

You need to change

JavaScript

(please also note the syntax error, missing &&) to

JavaScript

I just added a few line breaks in order to make the pointcut more readable.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement