Where to put @Bean in Spring Boot?

It is pretty much a matter of preference, but it is generally considered best practice to put exposed beans in configuration classes, which are logically grouped.

For example, you might have several configuration classes with a number of beans contained within each: An authentication configuration class with beans for AuthenticationProvider or UserDetailsService; a Thymeleaf configuration class containing beans for various Thymeleaf dialects, etc.


Actually, it is your choice there is no spring standard present to tell which one is best but while defining a class OOP design principles says A class should be loosely coupled and highly cohesive, should follow Single Responsibility Principle (SRP), Here

Coupling --> Degree of knowledge a class has about another class

Cohesion --> Degree which tells how well focused your class is

SRP --> A class should have only one responsibility, there should be only one reason to change a class.

So according to cohesion and SRP principle class should be well focused and have only one responsibility.

Here in your case you have only 2 beans but in future, these beans might increase. So should follow your second point and create another class for your bean declaration.

And In my choice should even create more configuration classes, So one configuration class should have a similar type of beans.