Replacing generated beans

You can also customize Spring Boot auto-configuration by defining certain beans yourself in your Spring application, so Spring Boot won't use default configuration for those beans.

Normally, beans you declare explicitly disable any auto-created ones. Let's see the following example:

@Bean 
public DataSource dataSource() { 
   return new EmbeddedDatabaseBuilder(). 
         setName("AccountDB").build(); 
} 

In the preceding code, we have explicitly defined a DataSource bean; your DataSource bean configuration stops Spring Boot from creating a default DataSource. Bean names are often not important. It works with XML-based configuration, annotation, and/or Java-based configuration.

Let's see another way of customizing Spring Boot autoconfiguration. ...

Get Mastering Spring Boot 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.