In spring 4 @Autowired is not working for class which extends Region which extends Map
giving exception
No qualifying bean of type [com.gemstone.gemfire.pdx.PdxInstance] found for dependency [map with value type com.gemstone.gemfire.pdx.PdxInstance]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
It is probably assuming a collection injection point. How to do a work around. Even adding a @Qualifier is giving same error.
So, if I am following you correctly (hard to know for sure without a code snippet), I assume you have something like this...
class MyRegion<K, V> extends Region<K, V> {
...
}
Then...
@Component
class MyApplicationComponent {
@Autowired
private MyRegion<?, PdxInstance> region;
}
Yeah?
So, the problem is, you cannot use @Autowired to inject, or auto-wire a Region reference into your application components. You must use @Resource, like so...
@Component
class MyApplicationComponent {
@Resource(name = "myRegion")
private MyRegion<?, PdxInstance> region;
}
The reason is, Spring (regardless of version), by default, whenever it autowires a "Map" into an application component attempts to create a mapping of all Spring beans defined in the Spring ApplicationContext. I.e. bean ID/Name -> bean reference.
So, given...
<bean id="beanOne" class="example.BeanTypeOne"/>
<bean id="beanTwo" class="example.BeanTypeTwo"/>
...
<bean id="beanN" class="example.BeanTypeN"/>
You end up with an auto-wired Map in your application component of...
@Autowired
Map<String, Object> beans;
beans.get("beanOne"); // is object instance of BeanTypeOne
beans.get("beanTwo"); // is object instance of BeanTypeTwo
...
beans.get("beanN"); // is object instance of BeanTypeN
So, what is happening in your case is, there are no beans in the Spring context defined in terms of type (GemFire's) PdxInstance. That is the data in your (custom) Regions(s). So when it tries to assign all the beans in the Spring context or your autowired (custom) Region, which Sprig identifies as a "Map", it cannot assign beans of other types to PdxInstance, taking "Generic" type into account.
So, in short, use @Resource to autowire any GemFire Region, custom or otherwise.
Also, I question the need to "extend" a GemFire Region. Perhaps it is better to use a wrapper ("composition") instead.
Hope this helps.
Cheers!