Spring injection question
I have a static class ResourceFetcher
with a static method fetchResource(String reference)
. I want to inject the resource returned by it into another class JobRunner
. Can anyone specify the cleanest way of doing this?
I do not want to pass ResourceFetcher
into JobRunner
. In fact, I have an enum
with set of keys, and I need to pass a map of key-value pairs into JobRunner
with values obtained by invoking fetchResource
.
Onething I want to clarify is that ResourceFetcher
class' fetchResource
returns an object of ty开发者_如何学Pythonpe String
Thanks in advance.
<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.
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.
精彩评论