ust*_*tun 2 java spring exception spring-el
我在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"/>
Run Code Online (Sandbox Code Playgroud)
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}" ->
Run Code Online (Sandbox Code Playgroud)
这是我的xml中的初始bean声明:
<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">
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?我在我的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();
Run Code Online (Sandbox Code Playgroud)
这是我的完整application-context.xml和pom.xml:http://paste.pocoo.org/show/494260/和http://paste.pocoo.org/show/494262/
确保你使用ApplicationContext而不是BeanFactory.BeanFactory不支持一些高级功能ApplicationContext,包括Spring EL.
也可以看看:
| 归档时间: |
|
| 查看次数: |
2722 次 |
| 最近记录: |