0

I'm implementing a map as a Spring Bean; key type is a custom enum, and another custom class is the value type. I've been following this answer closely. Here's be bean declaration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        ">

<bean id="ABTester" class="...ABTester">
    <property name="fractionB" value="${DEFAULT_VALUE:0.0}"/>
    [...]
</bean>

<bean id="ABTesterNl" class="...ABTester">
    <property name="fractionB" value="${DEFAULT_VALUE_NL:0.0}"/>
    [...]
</bean>

<util:map id="ABTesters" key-type="...Language" value-type="...ABTester">
    <entry key="#{T(...Language).EN}" value-ref="ABTester"/>
    <entry key="#{T(...Language).NL}" value-ref="ABTesterNl"/>
</util:map>
</beans>

In my class, I try to initialize the map like this:

    @Resource(name = "ABTesters")
    Map<Language, ABTester> ABTesters

However, when compiling, I get this error:

Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ABTesters' available

Injecting the ABTester bean in the same class works fine like this (same for ABTesterNl):

    @Autowired
    ABTester ABTester

I have also tried numerous variations, e.g. using @Autowire instead of @Resource for injecting the bean, (not) explicitly specifying the map's key and value types and syntactical variations for the key definitions of the entries. Anyway, the answer linked above and other examples as well as the documentation seem to point to the approach I have listed above.

Not sure how to debug further... What am I missing?

Carsten
  • 1,732
  • 26
  • 52

0 Answers0