Unable to read properties in Spring
<p>I have a properties file in <code>src/main/resources</code>.</p>

<p>Spring 4.0 and Java 1.8 project.</p>

<p>mock.properties</p>

<pre><code>key=test
</code></pre>

<p>WEB-INF/web.xml</p>

<pre><code>&lt;context-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    &lt;param-value&gt;/WEB-INF/mvc-dispatcher-servlet.xml&lt;/param-value&gt;
&lt;/context-param&gt;
</code></pre>

<p>WEB-INF/mvc-dispatcher-servlet.xml</p>

<pre><code>&lt;context:component-scan base-package="com.x.y.z.*"&gt;
&lt;/context:component-scan&gt;
&lt;context:annotation-config /&gt;
&lt;context:spring-configured /&gt;
&lt;context:property-placeholder location="classpath:mock.properties"
    order="-1" ignore-resource-not-found="true" ignore-unresolvable="true" /&gt;
&lt;mvc:annotation-driven /&gt;
</code></pre>

<p>Controller.java ... I can access the value of property key in controller.</p>

<pre><code>@Controller
@RequestMapping("/xyz")
public class EC2Controller {
@Value("${key}")
String v;
}
</code></pre>

<p>Helper.java  ... Can't access any property.Always gets "null"</p>

<pre><code>@Component
public class Helper {
@Value("${key}")
String v;
}
</code></pre>

<p>I also tried various options suggested on forums and spring docs but helper is just not able to read the prop.I tried following as well</p>

<pre><code>@Configuration
@PropertySource("classpath:mock.properties")
public class Helper {
@Value("${key}")
String v;

@Bean
public static PropertySourcesPlaceholderConfigurer      
propertySourcesPlaceholderConfigurer() {
   return new PropertySourcesPlaceholderConfigurer();
}
}
</code></pre>

<p>and </p>

<pre><code>@Configuration
@PropertySource("classpath:mock.properties")
public class Helper {
@Autowired
Environment env;
String v = env.getProperty("key");
}
</code></pre>

<p>nothing works.</p>