Announcement Announcement Module
No announcement yet.
Trouble autowiring a util:map Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble autowiring a util:map

    This is a continuation of my earlier util:map issue. For the time being, I'm now defining a map with string keys and just reversing the map post-construction.

    Here's an excerpt from my context:
        <util:map id="reverseWorkflowIdentifierMap" key-type="java.lang.String"
            <entry key="New PostPaid">
                <bean class="somepackage.WorkflowIdentifier"
                      p:customerType="NEW" p:paymentArrangement="PostPaid" p:queueType="TLG POSTPAID"/>
    Here's an excerpt from my class:
        private Map<String, WorkflowIdentifier> reverseWorkflowIdentifierMap;
    At load time, I see the following:
    Caused By: org.springframework.beans.factory.NoSuchBeanDefinitionException:
    No matching bean of type [somepackage.WorkflowIdentifier] found for dependency
    [map with value type somepackage.WorkflowIdentifier]:
    expected at least 1 bean which qualifies as autowire candidate for this dependency.
    Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    What am I doing wrong?

  • #2
    Autowiring collections can get a bit tricky, as that's the same way you specify "give me ALL objects in the context of this type". I've never tried it, but if I were a betting man, I'd suggest seeing if a @Qualifier solves the problem i.e.

        private Map<String, WorkflowIdentifier> reverseWorkflowIdentifierMap;
    Hope this helps
    - Don


    • #3
      Good thought. No luck, though. The error message changed, just to include the new Qualifier annotation. It seems to me like Spring is trying to be too smart for me, trying to find multiple WorkflowIdentifier objects to store into the Map, instead of a single Map.


      • #4
        Actually, this last comment I made caused me to realize the best way to do this. I'm just going to let Spring do what it wants to do. Instead of defining a Map in the context, I'm just defining each of the WorkflowIdentifier instances that I need as top-level beans, and by using "@Autowired" on the Map, Spring injects each of those WorkflowIdentifier objects into the Map. It works.