Announcement Announcement Module
Collapse
No announcement yet.
accessing a beans get function - ?injection to another bean? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • accessing a beans get function - ?injection to another bean?

    Hi all - new to spring and the way spring handles the underlying data (that I need to get to

    I've got a project where I'm instantiating beans to handle incoming request header values. The filter bean that is defined is correctly picking these up and creating its internal map structure.

    Now I need to get this map into another bean ..

    What I have so far has not worked....

    In a nutshell, I'm trying to set the Map of my second bean by accessing a getHeaderMap of the first filter bean.


    <bean id="requestHeaderFilter" class="my.web.RequestHeaderFilter">
    <property name="headerMapping">
    <map>
    <entry key="eid" value="eid" />
    <entry key="displayName" value="displayName" />
    </map>
    </property>
    </bean>


    <bean id="headerRepo"
    class="my.web.HeaderCollection">
    <property name="backingMap" ref="requestHeaderFilter.getHeaderMapping()" />
    </bean>


    Any bean guidance would be helpful.. I'm currently also reading 'springbyexample' but just started...

    Thanks.

  • #2
    Hi,

    You can declare the map as another bean and inject it to both beans.

    Code:
    	<bean class="java.util.HashMap" id="map">
    		<constructor-arg index="0">
    			<map>
    				<entry key="eid" value="eid" />
    				<entry key="displayName" value="displayName" />
    			</map>
    		</constructor-arg>
    	</bean>
    Note that you can also use the util namespace to create the map.

    Comment


    • #3
      Ahh OK so my map bean gets passed into each other bean using something like

      <property name="headerMapping" ref="mapbean">

      Is that what you mean?

      Comment


      • #4
        Originally posted by akfoote View Post
        Ahh OK so my map bean gets passed into each other bean using something like

        <property name="headerMapping" ref="mapbean">

        Is that what you mean?
        Exactly

        Comment

        Working...
        X