When to use @autowired
? Is your goal to inject a class? But for that would not be @inject
?
@Autowired
private CreateTextMessageService service;
In this case the @autowired
is being used in a property.
But in the following example, it is being used in a set function. What does @autowired
do?
Example:
import org.springframework.beans.factory.annotation.Autowired;
public class Product {
private Integer price;
private String name;
private Type type;
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public Type getType() {
return type;
}
@Autowired
public void setType(Type type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}