私は、AbstractSingleBeanDefinitionParser のカスタム実装を使用して、Spring 構成で 3D ベクトルを定義できるようにしています。
<rbf:vector3d id="test_vector" delimeter=";" value="45;46;47"/>
それはうまく機能し、何ヶ月も問題なく使用しています. 昨日、次のように .properties ファイルで値を定義しようとしました。
test.properties には次のものがあります。
vector3d.value=1,2,3
そして、私が持っているxmlファイルには:
<context:property-placeholder location="test.properties"/>
<rbf:vector3d id="test_vector_with_properties" delimeter="," value="${vector3d.value}"/>
単体テストを実行しようとするとクラッシュし、次の例外が発生します。
Caused by: java.lang.NumberFormatException: For input string: "${vector3d.value}"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1222)
at java.lang.Double.parseDouble(Double.java:510)
at scala.collection.immutable.StringLike$class.toDouble(StringLike.scala:234)
at scala.collection.immutable.StringOps.toDouble(StringOps.scala:31)
at rb.foundation.spring.xml.Vector3DBeanDefinitionParser$$anonfun$1.apply(Vector3DBeanDefinitionParser.scala:25)
通常の Bean に .properties ファイルを使用すると、うまく機能するので、パーサーの実装で見落としていた微妙な点があると思います。これはscalaで書かれていますが、それに従うことができるはずです:
class Vector3DBeanDefinitionParser extends AbstractSingleBeanDefinitionParser
{
override def getBeanClass(element : Element) = classOf[Vector3D]
override def doParse(element: Element, builder: BeanDefinitionBuilder)
{
val delim = element.getAttribute("delimeter")
val value = element.getAttribute("value")
val values = value.split(delim).map(_.toDouble)
builder.addConstructorArgValue(values(0))
builder.addConstructorArgValue(values(1))
builder.addConstructorArgValue(values(2))
}
}
必要に応じて、キーの置換を喜んで追加します。それをどこでどのように行うかを知る必要があるだけです。
アイデア?