spring-cloud / spring-cloud/spring-cloud-commons
@RefreshScope proxy doesn't have an interface bound to it
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 751
- Forks
- 744
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
See https://github.com/spring-projects/spring-amqp/issues/1121
I have a @Bean annotated with @RefreshScope. Somewhere in the spring-amqp library, some code checks whether the connection factory is a RoutingConnectionFactory and looks up the target connection factory if it is. This is done by using instanceof, but in the case of @RequestScope, the bean is proxied (with JDK dynamic proxy), so the instanceof check doesn't work. Setting the proxy mode to TARGET_CLASS will still produce a JDK dynamic proxy.
This can be solved to change the type of the bean to its implementation, but that is not something we generally prefer. Shouldn't the proxy implement the interfaces that the target object has?
Reproduction:
Open the attached Spring boot project
Set a breakpoint in AbstractMessageListenerContainer.getConnectionFactory()
Debug the project and check that the instanceof check yields false.
Remove the @RefreshScope annotations in RoutingTestApplication.java
Debug again and see that the instanceof check yields true now.
I encountered this problem in spring-cloud Greenwich.SR3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached Spring Boot reproduction, then inspect AbstractMessageListenerContainer.getConnectionFactory() and RoutingTestApplication.java. Compare the instanceof result with and without @RefreshScope; done means the proxied bean still exposes the target connection factory interface so the check succeeds.
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