application-context.xmlに次の簡単な式があります。
<bean id="instrument" class="com.ustunozgur.Instrument" init-method="initialize" scope="prototype">
<property name="age" value="#{4}"/>
<property name="name" value="Violin"/>
Instrumentクラスは単純なPOJOです。ただし、次のエラーがスローされます。
[ERROR] ...nested exception is org.springframework.beans.TypeMismatchException:
Failed to convert property value of type 'java.lang.String' to required type
'int' for property 'age'; nested exception is java.lang.NumberFormatException: For input string:
"{4}" ->
これが私のxmlの最初のbeans宣言です:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
何が問題なのですか?pom.xmlにspring-core、spring-expression、spring-contextを含めました。コードを介して構成を行っていません。すべての構成はxmlを介して行われます。
PS:これはコマンドラインアプリケーションですが、原因である可能性はありますか?
PPS:ただし、次のコードは機能するため、XMLのspelのみが無視されるようです。
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("'Hello World'");
String message = (String) exp.getValue();
これが私の完全なapplication-context.xmlとpom.xmlです: http: //paste.pocoo.org/show/494260/とhttp://paste.pocoo.org/show/494262/