08-02-2023, 10:25 AM
As of Spring 3.2, this is no longer an issue. Spring now supports Autowiring of the results of generic factory methods. See the section entitled "Generic Factory Methods" in this blog post:
The key point is:
> In Spring 3.2, generic return types for factory methods are now
> properly inferred, and autowiring by type for mocks should work as
> expected. As a result, custom work-arounds such as a
> MockitoFactoryBean, EasyMockFactoryBean, or Springockito are likely no
> longer necessary.
Which means this should work out of the box:
<bean id="dao" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="com.package.Dao" />
</bean>
[To see links please register here]
.The key point is:
> In Spring 3.2, generic return types for factory methods are now
> properly inferred, and autowiring by type for mocks should work as
> expected. As a result, custom work-arounds such as a
> MockitoFactoryBean, EasyMockFactoryBean, or Springockito are likely no
> longer necessary.
Which means this should work out of the box:
<bean id="dao" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="com.package.Dao" />
</bean>