spring-projects / spring-projects/spring-framework

Fall back from cglib to JDK proxies when possible

Open
#31,634 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: core type: enhancement
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

I am using Spring Boot 2.7, which defaults to cglib proxies. I have a JavaConfig bean definition:

interface ServiceInterface {
  @Async void log()
}

@Bean
ServiceInterface myBean() {
  new Impl()
}

If the Impl class is not subclassable by cglib (in this case, it uses a static factory method and has a private constructor), context startup fails with a "cglib can't subclass" error. However, if the declared bean type is an interface, in my view the ProxyFactory ought to use a JDK proxy instead (in the first place, but certainly if cglib fails).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ProxyFactory and reproduce the JavaConfig case described in the issue, where the declared bean type is an interface but the implementation cannot be subclassed by cglib. Trace how proxy selection handles that failure and add a regression test showing that a JDK proxy is used when possible; done means context startup succeeds for this configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.