Skip to content

Misleading type information reported by BeanNotOfRequiredTypeFailureAnalyzer #26821

@garyrussell

Description

@garyrussell

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.

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions