Skip to content

@MockBean doesn't work with @Timed annotated components #6665

Closed
@chornyi

Description

@chornyi

Similar to #6405

When applying @MockBean annotation to a component that has methods annotated with com.codahale.metrics.annotation.Timed, following exception is thrown on application startup:

The bean 'BeanName' could not be injected as a 'com...BeanName' because it is a JDK dynamic proxy that implements:


Action:

Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.


Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'BeanName' is expected to be of type [com...BeanName] but was actually of type [com.sun.proxy.$Proxy159]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.checkBeanNotOfRequiredType(DefaultListableBeanFactory.java:1423)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1402)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1057)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1019)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566)
    ... 67 more

This application does not use @EnableAsync or @EnableCaching. This is with Spring Boot 1.4.0.RELEASE

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions