Error message when I am entering a non String SpEL expression in spring-config.xml
I have created a spring application and when I am trying to enter a non-String SpEL expression in the spring-config.xml I get an error (but the project runs fine, since I am not doing anything wrong).
Here is an example :
InjectSimpleSpel.java :
public class InjectSimpleSpel {
private String name;
private int age;
private float height;
private boolean programmer;
private Long ageInSeconds;
//setters
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setHeight(float height) {
this.height = height;
}
public void setProgrammer(boolean programmer) {
this.programmer = programmer;
}
public void setAgeInSeconds(Long ageInSeconds) {
this.ageInSeconds = ageInSeconds;
}
//other methods
@Override
public String toString() {
return "Name :" + name + "\n"
+ "Age:" + age + "\n"
+ "Age in Seconds: " + ageInSeconds + "\n"
+ "Height: " + height + "\n"
+ "Is Programmer?: " + programmer;
}
}
and here is the part of the spring-config.xml that produces the error (all the value properties except from the first one):
<bean id="injectSimpleSpel" >
<property name="name">
<value>#{injectSimpleConfig.name}</value>
</property>
<property name="age">
<value>#{injectSimpleConfig.age + 1}</value>
</property>
<property name="height">
<value>#{injectSimpleConfig.height}</value>
</property>
<property name="programmer">
<value>#{injectSimpleConfig.programmer}</value>
</property>
<property name="ageInSeconds">
<value>#{injectSimpleConfig.ageInSeconds}</value>
</property>
</bean>
The error I get from the four value properties after the first one is like this one :
Cannot convert string #{injectSimpleConfig.age + 1} to target class int
请先登录再写评论。