@Lazy懒加载
@Scope(scopeName =“prototype” )设置多例模式,不加默认单例模式
@Lazy
@Component
@Scope(scopeName ="prototype" )
public class Drink {
@Value("橙汁")
private String name;
@Value("半糖")
private String sugar;
@Value("18")
private float price;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSugar() {
return sugar;
}
public void setSugar(String sugar) {
this.sugar = sugar;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public Drink() {
System.out.println("创建一杯饮料");
}
public Drink(String name) {
this.name = name;
}
public Drink(String name, String sugar) {
this.name = name;
this.sugar = sugar;
}
public Drink(String name, float sugar) {
this.name = name;
this.price = sugar;
}
public Drink(float sugar, String name) {
this.name = name;
this.price = sugar;
}
@Override
public String toString() {
return "Drink{" +
"name='" + name + '\'' +
", sugar='" + sugar + '\'' +
", price=" + price +
'}';
}
}