Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading type information reported by BeanNotOfRequiredTypeFailureAnalyzer #26821

Closed
garyrussell opened this issue Jun 8, 2021 · 0 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@garyrussell
Copy link
Contributor

Related to spring-projects/spring-retry#214

When using spring-retry with JPA repositories, the JPA repo proxy is (incorrectly) wrapped in a proxy that only implements Retryable.

We get a strange error when trying to inject this bean:

The bean 'testRepository' could not be injected as a 'com.example.demo.TestRepository' because it is a JDK dynamic proxy that implements:
	org.springframework.data.repository.CrudRepository

The logic here...

printer.printf("The bean '%s' could not be injected as a '%s' because it is a "
		+ "JDK dynamic proxy that implements:%n", ex.getBeanName(), ex.getRequiredType().getName());
for (Class<?> requiredTypeInterface : ex.getRequiredType().getInterfaces()) {
	printer.println("\t" + requiredTypeInterface.getName());
}

...simply appends the super-interface of TestRepository (CrudRepository) to the error message.

The actual exception message is:

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'testRepository' is expected to be of type 'com.example.demo.TestRepository' but was actually of type 'com.sun.proxy.$Proxy70'

$Proxy70 doesn't actually implement CrudRepository - only Retryable.

I believe the correct logic would be to use getActualType().getInterfaces() in the for loop.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 8, 2021
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 8, 2021
@philwebb philwebb added this to the 2.4.x milestone Jun 8, 2021
@scottfrederick scottfrederick self-assigned this Jun 15, 2021
@scottfrederick scottfrederick changed the title Misleading/Confusing Error Reported by BeanNotOfRequiredTypeFailureAnalyzer Misleading type information reported by BeanNotOfRequiredTypeFailureAnalyzer Jun 16, 2021
@snicoll snicoll modified the milestones: 2.4.x, 2.4.8 Jun 17, 2021
wilkinsona added a commit that referenced this issue Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants