Reputation: 191
package com.protect.shapes;
public class Triangle {
String Type = null;
String type = null;
public String getType() {
return Type;
}
public void setType(String Type) {
this.Type = Type;
}
public String gettype() {
return type;
}
public void settype(String type) {
this.type = type;
}
public void draw() {
System.out.println("Drawing " + type + " Triangle. " + Type);
}
}
Configuration file.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Project beans go here -->
<bean id="triangle" class="com.protect.shapes.Triangle">
<property name="Type" value="Equilateral">
</property>
</bean>
I was trying to check how Spring handles case sensitive property names but could not figure it out: for both the type
and Type
fields I Set I get the same output
"Drawing Equilateral Triangle. null".
Can you please explain this why and how can I instantiate Type
field.
Upvotes: 0
Views: 4091
Reputation: 13048
Spring can't find a setter for your Type
property:
setType
won't do because according to the java beans specification that refers to the type
propertysettype
is invalid because it's not recognized as a property setter according to the same specification.If you want an upper case names property it should begin with (at least) two uppercase letters, e.g.
public void setPType(...) {
...
}
and
<property name="PType" value="..."/>
Check section 8.8 of the specification.
Upvotes: 1