【发布时间】:2011-05-07 00:58:06
【问题描述】:
所以,我有一个包含以下条目的简单属性文件:
my.value=123
another.value=hello world
正在使用PropertyPlaceHolderConfigurer 加载此属性文件,它引用了上面的属性文件。
我有以下类,我正在尝试将这些属性加载到其中:
public class Config
{
@Value("${my.value}")
private String mValue;
@Value("${another.value}")
private String mAnotherValue;
// More below...
}
问题在于,mValue 和 mAnotherValue 始终为空...但在我的控制器中,该值被加载得很好。什么给了?
【问题讨论】:
-
Config类是否定义为spring bean?
-
不是吗?我将如何使用注释来做到这一点?
-
我尝试在课堂上使用“@Component”和“@Controller”,但都没有成功
-
那么它在
Controller中的工作原理是什么?你的 Controller 有什么不同? -
这让我很困惑...... Config 类和所有东西都在同一个包中......唯一的区别是,我的 Controller 可以工作,我实际上有一个请求映射。
标签: java spring spring-mvc