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

  • Home
  • SEARCH
  • 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 6572239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:58:51+00:00 2026-05-25T14:58:51+00:00

I have one class that has a list of objects of Daemon type. class

  • 0

I have one class that has a list of objects of Daemon type.

class Xyz {    
    List<Daemon> daemons;
}

My spring configuration looks like this.

<bean id="xyz" class="package1.Xyz">
   <property name="daemons" ref="daemonsList">
</bean>

<bean id="daemon1" class="package1.DaemonImpl1"/>
<bean id="daemon2" class="package1.DaemonImpl2"/>

<bean id="daemonsList" class="java.util.ArrayList">
        <constructor-arg>
            <list>
                <ref bean="daemon1" />      
                <ref bean="daemon2" />
            </list>
        </constructor-arg>
</bean>

Now instead of explicitly wiring each daemon implementation in list, is it possible to autowire all beans of type Daemon automatically in list. Problem I am trying to solve is, If someone creates a bean of new implementation of Daemon class and forgets to wire it into list.

I have seen this question somewhere on stackoverflow but not able to find that again. Apologies for it.

  • 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-05-25T14:58:51+00:00Added an answer on May 25, 2026 at 2:58 pm

    It should work like this (remove the ArrayList bean from your XML):

    public Class Xyz {    
    
        private List<Daemon> daemons;
    
        @Autowired
        public void setDaemons(List<Daemon> daemons){
            this.daemons = daemons;
        }
    
    }
    

    I don’t think there’s a way to do this in XML.


    See:
    3.9.2. @Autowired and @Inject:

    It is also possible to provide all beans of a particular type from the
    ApplicationContext by adding the annotation to a field or method that
    expects an array of that type:

    public class MovieRecommender {
    
      @Autowired
      private MovieCatalog[] movieCatalogs;
    
      // ...
    }
    

    The same applies for typed collections:

    public class MovieRecommender {
    
      private Set<MovieCatalog> movieCatalogs;
    
      @Autowired
      // or if you don't want a setter, annotate the field
      public void setMovieCatalogs(Set<MovieCatalog> movieCatalogs) {
          this.movieCatalogs = movieCatalogs;
      }
    
      // ...
    }
    

    BTW, as of Spring 4.x, these lists can be ordered automatically using the @Ordered mechanism.

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

Sidebar

Related Questions

I have a generic class that has one type parameter (T). I needed to
I have three files: one called sql.php witch has a class db that I
I have a class that contains a boolean field like this one: public class
I have a class that contains objects of two other classes. I need one
I have a list of objects say, List. The Entity class has an equals
I have a list of objects similar to the one below ( MyData class)
I have a class that looks like this: public class MyModel{ public int TheId
I have a large-ish project that contains one class that reads from a file
I'm creating a class that will have one public method, which returns a value
I'm using Java. I want to have a setter method of one class that

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.