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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:43:54+00:00 2026-06-13T23:43:54+00:00

with Java based configuration, i am trying to convert a map that maps enums

  • 0

with Java based configuration, i am trying to convert a map that maps enums to bean references to be in pure java config (currently in XML & works) but can’t seem to find anything in the documentations;

Currently, my XML like so;

<util:map id="colourHanders" key-type="com.example.ColourEnum"
          value-type="com.example.ColourHandler">
    <entry key="white" value-ref="whiteColourHandler"/>
    <entry key="blue" value-ref="blueColourHandler"/>
    <entry key="red" value-ref="redColourHandler"/>
</util:map>

I’m sure it is easy but again, can’t find anything on the subject of how to represent this in Pure Java (so I don’t have any XML configuration files)..

Note; the ColourHandler beans are created using the @Component annotation, e.g..

@Component
public class RedColourHandler implements ColourHander{
.....
}

and the map of colourHandlers is referenced as so;

@Resource(name="colourHandlers")
    private Map<ColourHandlerEnum, ColourHandler> colourHandlers;

Thanks,

Ian.

  • 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-13T23:43:56+00:00Added an answer on June 13, 2026 at 11:43 pm

    You probably want something like this:

    @Configuration
    public class MyConfiguration {
        @Bean public Map<ColourEnum, ColourHandler> colourHandlers() {
            Map<ColourEnum, ColourHandler> map = new EnumMap<>();
            map.put(WHITE, whiteHandler());
            // etc
            return map;
        }
    
        @Bean public ColourHandler whiteHandler() {
            return new WhiteHandler();
        }
    }
    

    If you need to keep your handlers as @Components, then you can autowire them into the configuration class:

    @Configuration
    public class MyConfiguration {
        @Autowired private WhiteColourHandler whiteColourHandler;
    
        @Bean public Map<ColourEnum, ColourHandler> colourHandlers() {
            Map<ColourEnum, ColourHandler> map = new EnumMap<>();
            map.put(WHITE, whiteColourHandler);
            return map;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to migrate Spring from XmlApplicationContext to AnnotationConfigApplicationContext (more info: Java-based container configuration
I have been using the new feature of Spring 3.1.1 the java based configuration.
I'm using a java based uploading construct http://www.javaatwork.com/java-upload-applet/details.html that I tried running over night.
I am new to Spring programming and currently struggling with Spring 3.1's Java Based
I have previously used XML based configuration for my Spring app. Now, I want
I'm trying to call a Java based, WS-Security enabled web service over https using
I am using java annotation based configuration for initializing ehcache based caching, with Spring
I am using Spring 3 ,java based configuration, with BootStrap. I have downloaded the
Just a general question, when you define a Java based configuration web app. Ie.e
i have three java based web application app1,app2 and app3 at production. All 3

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.