5 Replies Latest reply on Nov 23, 2012 4:48 PM by gavind

    Inject a Map - Spring DI alternative

    gavind

      I'm a newbie, and looking to replace Spring DI with CDI. I'm trying to find a simple way to replace a similar configuration to the one below in Spring with a weld CDI equivalent-

       

      {code:xml}

      <bean id="CreditCardHandlerMap" class="org.springframework.beans.factory.config.MapFactoryBean">

              <property name="targetMapClass">

                  <value>java.util.HashMap</value>

              </property>

              <property name="sourceMap">

                  <map key-type="com.mycompany.enums.CreditCardTypeEnum">

                      <entry key="VISA" value-ref="VisaHandler"/>

                      <entry key="MASTERCARD" value-ref="MasterCardHandler"/>

                  </map>

              </property>

          </bean>

      {code}

      and

       

      {code}

      public enum CreditCardTypeEnum implements IsSerializable, Serializable {

                VISA("Visa"),

                MASTERCARD("Mastercard");

       

                private String description;

       

                private CreditCardTypeEnum(String description) {

                          this.description = description;

                }

       

                @Override

                public String getDescription() {

                          return this.description;

                }

      }

      {code}

      I've searched for a simple solution, and have not been able to find one. Is there a simple approach?