My application contains the following classes among others:
SpringMainApplication:
@SpringBootApplication
@ComponentScan(basePackages = {"com.foo"})
class com.foo.appl.SpringMainApplication {
... some code...
}
An interface that should be used to autowire a field:
interface com.foo.bar.ClassToAutowire {
}
And another class that uses said interface for a field:
@Component
class com.foo.appl.pack.ImplementationClass {
@Autowired
ClassToAutowire autoClass;
@Scheduled(fixedRate = 60000)
public void startStuff() {
// do something...
}
}
But the field won't autowire:
Field autoClass in com.foo.appl.pack.ImplementationClass required a bean of type 'com.foo.bar.ClassToAutowire' that could not be found.
Action:
Consider defining a bean of type 'com.foo.bar.ClassToAutowire' in your configuration.
I guess Spring doesn't like my package-structure?
com.foo.bar.ClassToAutowire
com.foo.appl.SpringMainApplication
com.foo.appl.pack.ImplementationClass
Does the @SpringBootApplication
have to be in the root package and all components must be in subpackages? If so, how do I solve my "problem", because the ClassToAutowire
comes from an imported JAR.
When changing the basePackge
to com.foo.bar
the application starts, but then the scheduled method won't run.
Thanks