Inject bean from a different folder

Viewed 380

I have a project structure that looks like this:

enter image description here

In My Groovy folder contains a class marked with @Component that I Want to inject in another class inside the java folder. However spring can't find the bean to inject, when I move the class marked with @Component to the java folder it works fine. How can I make spring aware of the groovy folder?

1 Answers

You can use @ComponentScan at your Spring application (annotated with @SpringBootApplication) to scan components from other packages.

@ComponentScan(basePackages = "com.stackoverflow.other.package")

See https://www.baeldung.com/spring-component-scanning.

Related