Issue
I've decided I want to register Spring Beans in the java code and I want to know how it should be done the best way possible.
I inject deps through constructor (do not want to use @Autowire - I consider it almost antipattern) and I can make it work by adding:
@Configuration
public class Config {
@Bean
public BeanType getBeanType() {
return new BeanType();
}
}
BUT. Where the @Configuration part should go?
Should I make a Config class per package? (trying to make code closed in packages/domains)
Should I register them in inner classes of classed that are using them?
How should it be done? Internet is full of antipatterns, I want to find the way that is thought through carefully.
Thanks in advance for any advice.
Solution
I hesitated whether should I click on Close as it's opinion based but then decided to describe our practice.
We define multiple configuration classes and split them logically e.g. - one config for Db/hibernate/Transaction, another one for Queue/Listeners etc., one more for Logs and all related, plus one for No SQL connect etc. etc.
Answered By - StanislavL
Answer Checked By - Clifford M. (JavaFixing Volunteer)