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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:21:35+00:00 2026-05-26T00:21:35+00:00

I have a number of classes of the same type ( com.project.abc.abs.Agent ) annotated

  • 0

I have a number of classes of the same type (com.project.abc.abs.Agent) annotated like so;

@Component("WEB.Agent-1"), @Component("WEB.Agent-2"), @Component("WEB.Agent-3")… etc. For now assume that all classes are in the same package (com.project.abc.web.Agent1...).

These classes are all singletons, and I want to load them dynamically into a central ‘Agent manager’ class. I.e. every time a new agent class is added with the @Component("WEB.Agent-#") annotation it is picked up without having to make changes to the Agent Manager. In the AgentManager class I need some method to load any component that matches the name “WEB.Agent-#” (where # is a number or some unique ID) is this possible using any methods in Spring?

If not I’m assuming that I would need to go about loading all classes from a particular folder/package?

  • 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-26T00:21:35+00:00Added an answer on May 26, 2026 at 12:21 am

    You can do this with ClassPathScanningCandidateComponentProvider and add an exclude filter that gets rid of things that don’t match your pattern:

    ClassPathScanningCandidateComponentProvider scanner =
        new ClassPathScanningCandidateComponentProvider();
    
    scanner.addIncludeFilter(new AnnotationTypeFilter(Component.class));
    scanner.addExcludeFilter(new TypeFilter(){
        public boolean match(MetadataReader metadataReader, 
                             MetadataReaderFactory metadataReaderFactory){
            return metadataReader.getAnnotationMetadata()
                     .getAnnotationAttributes(Component.class.getName())
                     .get("value").matches("WEB.Agent-[0-9]+");
        }
    });
    
    for (BeanDefinition bd : scanner.findCandidateComponents("com.project.abc.web.Agent1"))
        System.out.println(bd.getBeanClassName());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of static classes that contain tables like this: using System;
I have a project with a number of different classes querying and modifying data
I have a number of classes which all share the same methods, only with
if i have a number of classes with something like @property (nonatomic, retain) NSString*
I have a base class called Component which has a number of classes derived
I have a couple of classes, all derived from the same base type. class
Suppose I have a number of related classes that all have a method like
I have a number of classes that are all related conceptually, but some more-so
I have a number of data classes representing various entities. Which is better: writing
I have a number of DAO classes that extend SqlMapClientDaoSupport, and call getSqlMapClientTemplate() to

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.