I am writing a spring boot bases application. There are 5 such separate projects and all of the projects share 100+ java files in common and I decided to make a jar out of these common java files. I have followed below steps to achieve this:
- Created jar with the common files.(Some are annotated with @Component and some are not)
- Imported the jar into those 5 applications and used @ComponentScan annotation to scan both the imported jar package and depended project package. This did not work so I have tried installing the jar in local maven repo and adding pom dependency of jar in pom.xml of depended project and still it did not work.
The issue I am facing is even after using the jar in the project, spring boot gives below error:
APPLICATION FAILED TO START
Description:
Field userService in main.java.rest.UsersController required a bean of type 'main.java.service.UserService' that could not be found.
Action:
Consider defining a bean of type 'main.java.service.Something' in your configuration.
But I have annotated Something.java with @Component.
I don't understand where am going wrong or if am missing something here. But it works when I write:
@Bean
public Something getSomething(){
return new Something();
}
But I cannot write such methods for 100+ components. Is there a way to get all beans scanned with one configuration class or any separate approach to achieve this?
Possible duplicate of 'Field required a bean of type that could not be found.' error spring restful API using mongodb, but I tried those approaches and still facing same error.