Results 1 to 4 of 4

Thread: Trouble autowiring a util:map

  1. #1
    Join Date
    Jan 2006
    Location
    Seattle, Washington
    Posts
    467

    Default 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:
    Code:
        <util:map id="reverseWorkflowIdentifierMap" key-type="java.lang.String"
                  value-type="somepackage.WorkflowIdentifier">
            <entry key="New PostPaid">
                <bean class="somepackage.WorkflowIdentifier"
                      p:customerType="NEW" p:paymentArrangement="PostPaid" p:queueType="TLG POSTPAID"/>
            </entry>
             ...
        </util:map>
    Here's an excerpt from my class:
    Code:
        @Autowired
        private Map<String, WorkflowIdentifier> reverseWorkflowIdentifierMap;
    At load time, I see the following:
    Code:
    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. #2
    Join Date
    Nov 2005
    Posts
    113

    Default

    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.

    Code:
        @Autowired
        @Qualifier("reverseWorkflowIdentifierMap")
        private Map<String, WorkflowIdentifier> reverseWorkflowIdentifierMap;
    Hope this helps
    - Don

  3. #3
    Join Date
    Jan 2006
    Location
    Seattle, Washington
    Posts
    467

    Default

    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. #4
    Join Date
    Jan 2006
    Location
    Seattle, Washington
    Posts
    467

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •