Announcement Announcement Module
Collapse
No announcement yet.
How to config the int bean property value in spring xml? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to config the int bean property value in spring xml?

    Ok, here's my config file

    Code:
    <bean id="websiteConfig" class="org.springframework.beans.factory.config.MapFactoryBean">
        <property name="sourceMap">
            <map>
                <entry>
                    <key><value>time</value></key>
                    ??????
                </entry>
            </map>
        </property>
    </bean>
    Basically, I want to put an integer as the value, but if I replace the ?????? with <value>3</value> I'll only get a String, so how do I specify an integer?

  • #2
    Hi

    Try...

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    
    	<bean id="websiteConfig" class="org.springframework.beans.factory.config.MapFactoryBean">
    		<property name="sourceMap">
    			<map>
    				<entry key="time">
    					<value type="java.lang.Integer">3</value>
    				</entry>
    			</map>
    		</property>
    	</bean>
    
    </beans>
    The value is actually typed as an Integer reference object, but that is a Java issue and not something that Spring can do anything about.

    Cheers
    Rick

    Comment


    • #3
      The value element supports an optional "type" attribute. That does the trick.

      This works:
      Code:
          <property name="sourceMap">
            <map>
              <entry key="time">
                <value type="java.lang.Integer">3</value>
              </entry>
            </map>
          </property>
      Regards,
      Andreas

      Comment

      Working...
      X