- Mastering Spring 5.0
- Ranga Rao Karanam
- 98字
- 2021-07-02 22:12:07
An example of CDI
When we use CDI, this is what the annotations on the different classes would look like. There is no change in how we create and launch the Spring application context.
CDI marks no differentiation between @Repository, @Controller, @Service, and @Component. We use @Named instead of all the preceding annotations.
In the example, we use @Named for DataServiceImpl and BusinessServiceImpl. We use @Inject to inject dataService into BusinessServiceImpl (instead of @Autowired):
@Named //Instead of @Repository
public class DataServiceImpl implements DataService
@Named //Instead of @Service
public class BusinessServiceImpl {
@Inject //Instead of @Autowired
private DataService dataService;