Issue
If I create some classes, can I automatically @Autowire
those classes somewhere else without using the @Bean
, @Component
, @Service
? Or if I want to @Autowire
a class somewhere else, do I need to use the annotations described before?
I want to @Autowire
a class to another that uses the @Configuration
and @ComponentScan
annotation
For example:
public class SomeClass{
//do Something
}
or
@Bean
public class SomeClass{
//do Something
}
to achieve this..
@Configuration
@ComponentScan("some.package")
public class SomeOtherClass{
@Autowire
private SomeClass someClass;
}
Solution
If i create some class, can i automatically @Autowire that class somewhere else without using the @Bean, @Component, @Service
No
You can read more about creating Spring beans.
Answered By - rkosegi
Answer Checked By - Candace Johnson (JavaFixing Volunteer)