June 2018
Intermediate to advanced
408 pages
11h 23m
English
In the previous section, we saw how to configure a bean using XML-based configuration. In this section, we will see the Java-based configuration. The same as XML, Java-based configuration also injects dependency explicitly. The following example defines the Spring bean and its dependencies:
@Configurationpublic class AppConfig { @Bean public CustomerService showCustomerAccountBalance() { return new CustomerService(); } @Bean public BankingService getBankingService() { return new BankingService(); } }
In the Java-based configuration, we must annotate the class with @Configuration, and the declaration of the bean can be achieved with the @Bean annotation. The previous example of a Java-based configuration is equivalent ...
Read now
Unlock full access