I am trying to load a properties file into a Spring bean and then inject that bean into a class.
The only part I can't get to work seems to be using the @Resource 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.
[EDIT] - I originally thought using the @Resource was the best way but the proposed solution I found easier.
I saw this solution in another post:
Reference Solution Link: Inject Property Value into Spring - posted by DON
Credit to Don for the post but I just wasn't sure how to finish it with the @Resource.
Debugging Results:
The variable value appProperties
is always null. It's not being injected.
Spring Config.
Sample Class:
package test;
import java.util.Properties;
import javax.annotation.Resource;
public class foo {
public foo() {}
@Resource private java.util.Properties appProperties;
}
Based on the advice in the approved solution below. Here are the changes I made.
Solution Update:
Spring Config:
Java Class:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…