ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Five Things I Love About Spring
Subject:   Some errors in the code
Date:   2005-05-12 15:44:17
From:   Russell_Healy

The constructor for CommandLineView constructs a RentABike using new RentABike - there is no concrete implementation of RentABike.



More importantly, clv does not have a setRentABike method, so the Assembler is not able to do the injection.



Also, I do not understand why CommandLineView has a main method.



CommandLineView should look more like this:


public class CommandLineView {


private RentABike rentaBike;


public CommandLineView( ) {
//nothing to do here
}


public void setRentABike(RentABike rentABike){
this.rentABike = rentABike;
}


public void printAllBikes( ) {
System.out.println(rentaBike.toString( ));
Iterator iter = rentaBike.getBikes().iterator( );
while(iter.hasNext( )) {
Bike bike = (Bike)iter.next( );
System.out.println(bike.toString( ));
}
}
}


I hope this helps


Russell