• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to declare auto-wiring for more than one dependent beans

 
Ranch Hand
Posts: 33
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I was checking some tutorials on Spring auto-wiring. In most of (almost all) tutorials have only one dependant beans.
But if the class (bean) has more then one dependant beans, how to define auto-wiring with them.

Say,



Can you declare multiple autowiring values for bean object of A?

Regards,
Jay Shukla
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,

You just put @Autowired annotation on every property that you want to be autowired
 
Jay B Shukla
Ranch Hand
Posts: 33
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for but how to declare then in XML?
 
Jay B Shukla
Ranch Hand
Posts: 33
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jayesh but in that all properties have to auto-wired in same way (e.g. byName or byTpye) etc OR you can declare properties to be auto wired in multiple.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no restriction, that you need to use in same way, you can have one property autowired by name and other by type.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class A
{
@Autowired
public B b;

@Autowired
public C c;

@Autowired
public D d;
}

It doesn't matter how many dependencies Class A has. You can autowire all the dependencies of Class A. But the main important thing is Class A itself should be a spring bean. Also, one important thing is Spring is encouraging usage of Annotation rather than XML for configuration. You can refer to one of these posts - Springboot
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic