O'Reilly logo

Hands-On High Performance with Spring 5 by Dinesh Radadiya, Prashant Goswami, Pritesh Shah, Subhash Shah, Chintan Mehta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Java-based configuration

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required