Reading a map from yaml in Java getting null
<p>I am getting a problem in reading my yaml through java, using spring. Let me show the code first</p>

<pre><code>@Component
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "countries")
public class UserLimitReader {

    private HashMap&lt;String, Integer&gt; orders;

    private HashMap&lt;String, Integer&gt; requests;

    public HashMap&lt;String, Integer&gt; getOrders() {
        return orders;
    }

    public void setOrderRedeemableLimit(HashMap&lt;String, Integer&gt;         orders) 
{
        this.orders= orders;
}

public HashMap&lt;String, Integer&gt; getRequests() {
    return requests;
}

public void setMonthlyRedeemableLimit(HashMap&lt;String, Integer&gt; requests) {
    this.requests= requests;
}
}
</code></pre>

<p>My yaml file:</p>

<pre><code>cassandra:
    hosts: localhost:9142, 127.0.0.1:9142
    keyspace: test
countries:
    orders:
      JPY: 1000
      USD: 1000
    requests:
      JPY: 100000
      USD: 100000
</code></pre>

<p>The spring context xml also has this:</p>

<pre><code>&lt;bean id="yamlProperties"
    class="org.springframework.beans.factory.config.YamlPropertiesFactoryBean"&gt;
    &lt;property name="resources"&gt;
        &lt;value&gt;classpath:config/application.yaml&lt;/value&gt;
    &lt;/property&gt;
&lt;/bean&gt;

&lt;context:property-placeholder
    properties-ref="yamlProperties" /&gt;
</code></pre>

<p>Now, the expectation that I have(had) is that, during the runtime of my spring-test application(the context xml is from my test resources, the yaml is also in my test), these values of orders and requests are set, but they are null. Also, note, there are other values in my yaml besides this that I am injecting using @Value(${...}), they are injected absolutely fine!</p>

<p>I looked at this: <a href="https://stackoverflow.com/questions/24917194/spring-boot-inject-map-from-application-yml/30540254#30540254">Spring Boot - inject map from application.yml</a></p>

<p>I have done virtually the same, but yet, my values are not set. Kindly help. </p>

<p>I was going through google, found this link: 
<a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/config/YamlPropertiesFactoryBean.html" rel="nofollow noreferrer">http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/config/YamlPropertiesFactoryBean.html</a></p>

<p>In this, it says, everything is read as a string and not a map. Is there any other class that supports reading of Yaml file the way they did it here: <a href="https://stackoverflow.com/questions/24917194/spring-boot-inject-map-from-application-yml/30540254#30540254">Spring Boot - inject map from application.yml</a></p>

<p>Or is my understanding of YamlPropertiesFactoryBean wrong?</p>

<pre><code>compile 'org.springframework:spring-core:4.2.+'
compile 'org.springframework:spring-beans:4.2.+'
compile 'org.springframework:spring-context:4.2.+'
compile 'org.springframework.boot:spring-boot:1.3.1.RELEASE'
compile 'org.springframework.boot:spring-boot-configuration-processor:1.3.1.RELEASE'
</code></pre>

<p>These are the dependencies in gradle. You might be wondering why I have spring-core and spring-boot, essentially, I don't want spring-boot, but without spring-boot, I don't get to add @EnableConfigurationProperties and @ConfigurationProperties, I honestly don't know if I can read the yaml content into a map without them. Hence those two dependencies are added, but if there's a way to remove them, I would be more than happy to remove those two dependencies.</p>

<p>Warm regards,
Pavan</p>