spring-cloud / spring-cloud/spring-cloud-commons

@RefreshScope proxy doesn't have an interface bound to it

Open
#636 0 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

routing-test.zip

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.