I am creating a Spring Boot library which can be used for my main projects. Is it not a good practice to annotate beans inside a custom library with @Component or @Service in Spring Boot? If so, why?
Because I saw an article saying,
Do not annotate each of your beans inside a library with @Component or @Service, but define them in an auto-configured module.
But I have 2 classes which I annotated as @Service
and inside those 2 classes they have some beans configured as follows,
@Service
public class SomeClass {
private @Autowired SomeClient client;
@Bean
public SomeClient client(@Value("${some.param}) String key) {
return new SomeClient(key);
}
public void use() {
// use the @Autowired client and do a task
}
}
When I used this library as a dependency in my main project it is working fine. But I need to know what is the best practice since that article says not to do this. But if I have to configure these inside AutoConfiguration
class it's tedious. So can anyone guide me to the correct path? Thank you.