This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Transfer Learning for Natural Language Processing (MEAP) and have Paul Azunre on-line!
See this thread for details.
Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

@Bean and @Component

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it true if I use @Component (or @Named), I should include this class' package in the component scan's base package, but if I use @Bean then I don't have to make this class be inside any component scan package ?
 
Saloon Keeper
Posts: 11881
253
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you need to declare the packages that need to be scanned for components, but the @Bean annotation is used on methods and not on classes, so component scanning doesn't apply to this annotation.
 
Ranch Hand
Posts: 240
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Bean is basically used on methods in @Configuration class.
@Component is used on class that signifies it is a Bean.

If you wrote all classes under the main package then you don't need @ComponentScan in Spring Boot. It will scan automatically.
But if you wrote the classes in different package than the main() method's class. Then you have to let Spring container know which packages to scan. You write them within @ComponentScan("xyz")
 
grapes are vegan food pellets. Eat this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic