As you know, constructor injection is a preferred pattern to add code to your dependency definition. For example, we can do the following:
@Component
public class TaskManager {
private ServiceReviewPublisher publisher;
@Autowired
public TaskManager(ServiceReviewPublisher publisher) {
this.publisher = publisher;
}
}
Notice that historically, developers would have to declare the constructor with an @Autowired annotation. This was so that the code can do proper injection. As of 4.3, that is no longer required. This will make the new code be this way:
@Component
public class TaskManager {
private ServiceReviewPublisher publisher;
public TaskManager(ServiceReviewPublisher publisher) {
this.publisher = publisher;
}
}
This makes this class one step closer to be a POJO.
No comments:
Post a Comment