1 / 4

Spring – Java-based Container Configuration

The central artifacts in Springu2019s new Java-configuration support are @Configuration-annotated classes and @Bean-annotated methods.<br><br>The @Bean annotation is used to indicate that a method instantiates, configures, and initializes a new object to be managed by the Spring IoC container. For those familiar with Springu2019s XML configuration, the @Bean annotation plays the same role as the element. You can use @Bean-annotated methods with any Spring @Component. However, they are most often used with @Configuration beans.

Ducat1
Télécharger la présentation

Spring – Java-based Container Configuration

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome To Ducat India Language | Industrial Training | Digital Marketing | Web Technology | Testing+ | Database | Networking | Mobile Application | ERP | Graphic | Big Data | Cloud Computing Apply Now Call us: 70-70-90-50-90 www.ducatindia.com Training & Certification

  2. Spring – Java-based Container Configuration The central artifacts in Spring’s new Java-configuration support are @Configuration-annotated classes and @Bean-annotated methods. The @Bean annotation is used to indicate that a method instantiates, configures, and initializes a new object to be managed by the Spring IoC container. For those familiar with Spring’s XML configuration, the @Bean annotation plays the same role as the element. You can use @Bean-annotated methods with any Spring @Component. However, they are most often used with @Configuration beans. Annotating a class with @Configuration indicates that its primary purpose is as a source of bean definitions. Furthermore, @Configuration classes let inter-bean dependencies be defined by calling other @Bean methods in the same class. The simplest possible @Configuration class reads as follows: The below simple example show usage of @Bean and @Configuration annotations. importorg.springframework.context.annotation.Bean; importorg.springframework.context.annotation.Configuration; importcom.companyname.projectname.customer.CustomerService; importcom.companyname.projectname.order.OrderService;

  3. @Configuration public class Application { @Bean publicCustomerServicecustomerService() { return new CustomerService(); } @Bean publicOrderServiceorderService() { return new OrderService(); } } The preceding configuration is exactly equivalent to the following Spring XML: < beans> < bean id="customerService" class="com.companyname.projectname.CustomerService"/> < bean id="orderService" class="com.companyname.projectname.OrderService"/> < /beans> Note that the method name and bean name in XML are exactly the same.

  4. Instantiating the Spring Container by Using AnnotationConfigApplicationContext Spring 3.0 introduced AnnotationConfigApplicationContext class which is implementation ApplicationContext interface. It is capable of accepting not only @Configuration classes as input but also plain @Component classes and classes annotated with JSR-330 metadata. When @Configuration classes are provided as input, the @Configuration class itself is registered as a bean definition and all declared @Bean methods within the class are also registered as bean definitions. When @Component and JSR-330 classes are provided, they are registered as bean definitions, and it is assumed that DI metadata such as @Autowired or @Inject is used within those classes where necessary. Read More: https://tutorials.ducatindia.com/java/spring-java-based-container-configuration/

More Related