Skip to content

@BeanInject - incorrectly marking bean as incompatible with specified type #1180

@rastislavpapp

Description

@rastislavpapp

I've got a class, that for production code is of one type, but in tests it's implemented manually, so has different type.

In production code I inject it via some Cache interface, but in tests I inject it with the TestCache type, because I want to call some init / cleanup methods in tests. @BeanInject looks for the bean id and finds it in the production blueprint context, so it marks it as a specific type (e.g. CaffeineCache), and then proceeds to say that I can't inject the bean to my TestCache field.

Suggested solution - either look for all the beans (in production and in test code), and only mark the bean as incompatible if all of them do not match the field type; or even better, if there's a bean declared in both prod and test code, use the correct one for determining the type, based on whether I'm injecting it in prod or test class.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions