0

Kind of a simple newbie question...I see how I can create a string object, but how would I create an int object?

Here is the xml code fragment from my context file:

<object id="myString" type="System.String">
  <constructor-arg value="foo" />    
</object>
<object id="myInt" type="System.Int32">
   <<<**** how do I set this ****>>>>
</object>
  • If you want to this to be able to inject some configuration values, then you should consider using the [`PropertyPlaceHolderConfigurer`](http://www.springframework.net/doc-latest/reference/html/objects.html#objects-factory-placeholderconfigurer). – Marijn Jul 03 '13 at 11:11

2 Answers2

3

Try this:

<object id="MyInt" type="System.Int32" factory-method="Copy">
  <constructor-arg index="0">
    <value>123</value>
  </constructor-arg>
</object>
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
0

Try this:

<object id="MyInt" type="System.Int32" factory-method="Parse">
  <constructor-arg index="0">
    <value>123</value>
  </constructor-arg>
</object>

For creating an object of primitive type System.Int32, you must use the factory-method="Parse". The attribute factory-method="Copy" doesn't works because it not exists in the type System.Int32 and you have to use a static method to do it.

Leandro Sá
  • 529
  • 5
  • 4