This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@autowired annotation

 
NareshAnkuskani Kumar
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using autowiring mechanism i am planning to establish relationships among the object.

if i annote a property with "@autowired" then should i have to declare the corresponding bean in applicationcontext.xml file.

please let me know.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you shouldn't. Also understand that by using @Autowire, you are not defining relationships in your objects. The relationship already exists via composition. @Autowire is just injecting one object into another object.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are just using @Autowired and not any @Components, then the base beans still need to be declared in your xml.

so


In order to get the ARepositoryImpl to be injected into AServiceImpl both need <bean> tags.



But the repository will be automatically injected into the service class.

If you have



Then the only thing you need in the xml is the context:component-scan tag to tell Spring which package to scan for @Component annotations. @Repository extends @Component so @Repository is an @Component.

hth

Mark
 
NareshAnkuskani Kumar
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark and others.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic