views:

42

answers:

2
A: 

If the fetchResource method is static on ResourceFetcher, why can't JobRunner simply refer to it? I don't see the need to inject ResourceFetcher.

duffymo
How would this be generic if ResourceFetcher if I want to transform 10 sql files in classpath into sql strings? To be precise, I had a static map as following in my JobRunner - Map<String, String> queryTempl where each values where sql queries fetched from ResourceFetcher as String. I was wondering if this was a right way to go about things.
kuriouskat
+2  A: 
<bean id="resource" class="com.x.y.ResourceFetcher" factory-method="fetchResource">
   <constructor-arg value="someReference"/>
</bean>

You can then inject resource into your JobRunner bean.

skaffman
Great. This is what I anticipated too. What if object returned by factory-method is not of type class ResourceFetcher?
kuriouskat
@kuriouskat: The bean type will be whatever is returned by the method, the type of `ResourceFetcher` is irrelevant to the outcome.
skaffman