Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9142277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:45:22+00:00 2026-06-17T09:45:22+00:00

In all the examples of autowiring that I have found, the example is about

  • 0

In all the examples of autowiring that I have found, the example is about one <bean> autowire attribute which is set for example to byName, and the has only one property value which is supposed to be set through autowiring.

My question is what if a <bean> has multiple properties that you want to set through autowiring? No one seems to explain that situation. Can someone explain if I can or if I should use autowire to set multiple properties in a bean? The following is an example of such a situation where I want to set the account and credit properties of the customer bean by autowiring:

<beans>
    <bean name="customer" class="ultratech.com.Customer" autowire="byName">
         <bean name="account"/>
         <bean name="credit>
    </beam>

    <bean name="account" class="ultratech.com.Account"/>
    <bean name="credit" class="ultratech.com.Credit"/>
</beans>

Also, please correct me if I’m wrong, but if I were to use annotation (@Autowire), then my problem is easily solved, since I would be able to add @Autowire to any property of a bean separately.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:45:23+00:00Added an answer on June 17, 2026 at 9:45 am

    [EDIT: edited to reflect on updated question]

    Your question is much more clear right now. You seem to think (if I follow your thinking properly), that in the autowire="byName" you are supposed to provide a bean name instead of byName value.
    That is not correct. The autowire attribute can take a few possible values and byName is one of those. When you set autowire to byName like here:

    <bean name="someBean" class="foo.bar.Baz" autowire="byName />
    

    then Spring will look at all the fields in someBean (foo.bar.Baz class) and attempt to wire all fields of this object on a per name basis. That is, (in your case) if a Customer class has a field account, Spring will look in its context and try to find a bean with name account to inject into the Customer bean.

    If you define two such beans:

     <bean name="customer" class="ultratech.com.Customer" autowire="byName" />
     <bean name="account" class="ultratech.com.Account" />
    

    then you are good to, if Customer is a class along this lines:

    public class Customer {
        (...)
        private Account account;
        (...)
    }
    

    Here is what your XML code snippet should look like, assuming that your Customer class has fields named account and credit:

    <beans>
        <bean name="customer" class="ultratech.com.Customer" autowire="byName" />
        <bean name="account" class="ultratech.com.Account" />
        <bean name="credit" class="ultratech.com.Credit" />
    </beans>
    

    Apart from “byName” autowiring, you can autowire:

    1. no – default – no autowiring
    2. byType – looks for a bean of the property type – be wary, though – only one bean of this type is allowed for autowiring byType; if there is more then one an exception is raised
    3. constructor – works just like byType, but looks for constructor parameters only; all of constructor parameters have to be satisfied with exactly one bean of each respective type

    See Spring reference for more info:
    http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/beans.html#beans-factory-autowire

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found that in all examples (include rails documentation) that I have seen
In all examples online that I have seen, when rendering meta-balls (level sets of
All examples in Qt show that one should use delegate classes to provide editors
Suppose we have abstract class A (all examples in C#) public abstract class A
I want to use CKEditor with DynamicData Web Site. The all examples that I
All the examples I have seen where the PropertyPlaceHolderConfigurer is used seem to be
Is it possible to virtualize both horizontally and vertically? All examples show one or
All examples I found was C# related, but I'm unfamiliar with it. My task
I have a main data store which has a big set of perfectly ordinary
In all examples of F# classes and records I see that records an classes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.