Skip to content

Spring AOP cannot generate CGLIB proxy for record class #35299

@ColorDreams

Description

@ColorDreams

Hi

I used record classes on Controller and Service to simplify the loading of Bean, but it doesn't seem to work, suggesting that CGLIB subclasses cannot be generated.

Controller: I can understand that, after all, it doesn't implement any interface, but Service has implemented the interface, and it still can't be enhanced by JDK Proxy.

The following is the pseudo code I used.

@Validated
@RestController
@RequestMapping("/users")
public record UserController(IUserService userService) {
    // some biz code...
}

@Service
public record UserServiceImpl(UserMapper userMapper) implements IUserService {
    // some biz code...
}

Interestingly, this code did not report errors at compile time, and IDEA can also identify their dependencies normally.

It would be great if the record class could be used on stateless bean, although Java is not Kotlin.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions