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 1108597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:06:31+00:00 2026-05-17T02:06:31+00:00

For example, I have created a slew of ‘test-my-service’ Objects in my Spring config

  • 0

For example, I have created a slew of ‘test-my-service’ Objects in my Spring config and each Object has data that concerns a contrived test scenario. Currently I am manually editing the Spring config every time I want to run a new scenario, or a List of scenarios. Is there a way I could add a prefix to a bean name, and then load all of the beans with that prefix (or suffix) into a List or Array? Something like….

<bean name="env1-test1"/>
<bean name="env2-test1"/>

This is the code that I ended up writing. I wasn’t able to get the beanFactory Object initialized from the example that I accepted earlier:

String[] beanNames = context.getBeanNamesForType(Inputs.class); 
for (String beanName : beanNames) { 
     if (beanName.startsWith("env")) { 
          System.out.println("Found a bean of type " + Inputs.class.getName()); 
          Inputs bean = (Inputs)context.getBean(beanName); 
          doTest(bean); 
     }
}
  • 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-17T02:06:32+00:00Added an answer on May 17, 2026 at 2:06 am

    You can use the ListableBeanFactory interface to retrieve all bean names, and then load the ones you’re interested in:

    private @Autowired ListableBeanFactory beanFactory;
    
    public void doStuff() {
       for (String beanName : beanFactory.getBeanDefinitionNames()) {
          if (beanName.startsWith("env")) { // or whatever check you want to do
             Object bean = beanFactory.getBean(beanName)
             // .. do something with it
          }
       }
    }
    

    Alternatively, if the target beans are all of the same type, then you can ask for them all by type, instead of by name, using ListableBeanFactory.getBeansOfType() or ListableBeanFactory.getBeanNamesForType().

    The injected ListableBeanFactory will be the “current” application context.

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

Sidebar

Related Questions

I have a loop created with each, check this example: $('.foo').each(function(i){ //do stuff });
I have created an test swt application which has some German special characters. When
I have created a little example,please have a look, http://jsfiddle.net/bWTwL/ I want to have
I have created a basic site using ASP.NET routing according to Mike Ormond's example
I have created a separate class (let's call it class2.cs for example) and want
I have created a CPTTradingRangePlot using the up-to-date sample code as an example. The
I have created a GUI that will setup the pivot table. For example, I
I have basic hello word example of Prime Faces. I have created dynamic web
I was already running a sub-website under following path http://example.com/sub-site/ Now, I have created
for example we have created file in c++ how to write content in this

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.