Sto sperimentando con Spring, sto seguendo il libro: Spring: un notebook per sviluppatori. Sto ottenendo questo errore:Spring: proprietà Bean non scrivibile o ha un metodo setter non valido
"Bean property 'storeName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?"
.. e sto abbastanza perduto.
devo una classe che implementa ArrayListRentABike
RentABike
:
import java.util.*;
public class ArrayListRentABike implements RentABike {
private String storeName;
final List bikes = new ArrayList();
public ArrayListRentABike() { initBikes(); }
public ArrayListRentABike(String storeName) {
this.storeName = storeName;
initBikes();
}
public void initBikes() {
bikes.add(new Bike("Shimano", "Roadmaster", 20, "11111", 15, "Fair"));
bikes.add(new Bike("Cannondale", "F2000 XTR", 18, "22222", 12, "Excellent"));
bikes.add(new Bike("Trek", "6000", 19, "33333", 12.4, "Fair"));
}
public String toString() { return "RentABike: " + storeName; }
public List getBikes() { return bikes; }
public Bike getBike(String serialNo) {
Iterator iter = bikes.iterator();
while(iter.hasNext()) {
Bike bike = (Bike)iter.next();
if(serialNo.equals(bike.getSerialNo())) return bike;
}
return null;
}
}
E il mio RentABike-context.xml
è questo:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="rentaBike" class="ArrayListRentABike">
<property name="storeName"><value>"Bruce's Bikes"</value></property>
</bean>
<bean id="commandLineView" class="CommandLineView">
<property name="rentaBike"><ref bean="rentaBike"/></property>
</bean>
</beans>
Tutte le idee per favore? Grazie mille! Krt_Malta
E se il nome proprietà è "MyDataSource" (property name = "MyDataSource"), allora la vostra setter ha bisogno di essere nominato come setMyDataSource(); non come setDataSource. –
Anche SPRING si aspetta getter con lo stesso tipo di ritorno della proprietà come getMyDataSource(). E sia getter/setter dovrebbero essere l'accessibilità a livello pubblico. –