Note that there are some explanatory texts on larger screens.

plurals
  1. POInjecting Properties using Spring & annotation @Value
    text
    copied!<p>I am trying to load a properties file into a Spring bean and then inject that bean into a class.</p> <p>The only part I can't get to work seems to be using the <em>@Resource</em> reference.Can someone connect the last piece for me? I get a null value every time. Doesn't seem to want to inject the value.</p> <p>[EDIT] - I originally thought using the <em>@Resource</em> was the best way but the proposed solution I found easier. </p> <p>I saw this solution in another post:</p> <p><strong>Reference Solution Link:</strong> <a href="https://stackoverflow.com/questions/317687/inject-property-value-into-spring-bean">Inject Property Value into Spring - posted by DON</a></p> <p>Credit to Don for the post but I just wasn't sure how to finish it with the <em>@Resource</em>.</p> <p><strong>Debugging Results:</strong> The variable value <code>appProperties</code> is always null. It's not being injected.</p> <p><strong>Spring Config.</strong> <img src="https://i.stack.imgur.com/Z4VJ3.png" alt="enter image description here"></p> <p>Sample Class:</p> <pre><code>package test; import java.util.Properties; import javax.annotation.Resource; public class foo { public foo() {} @Resource private java.util.Properties appProperties; } </code></pre> <p>Based on the advice in the approved solution below. Here are the changes I made.</p> <hr> <h1>Solution Update:</h1> <p>Spring Config: <img src="https://i.stack.imgur.com/LEp68.png" alt="enter image description here"></p> <p>Java Class: <img src="https://i.stack.imgur.com/sQBRT.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload