Building Microservices with Spring
上QQ阅读APP看书,第一时间看更新

Dependency injection pattern with Annotation-based configuration

As discussed in the previous two sections, we defined the DI pattern with Java-and XML-based configurations, and these two options define dependencies explicitly. It creates the Spring beans by using either the @Bean annotated method in the AppConfig Java file, or the <bean> element tag in the XML configuration file. By these methods, you can also create the bean for those classes which lie outside the application, that is, classes that exist in third-party libraries. Now let's discuss another way to create Spring beans, and define the dependencies between them by using implicit configuration through the Stereotype annotations.