【问题标题】:spring properties injection doesn't work @Value and <util:properties>弹簧属性注入不起作用 @Value 和 <util:properties>
【发布时间】:2011-08-06 09:36:41
【问题描述】:

我在使用 spring 的类中注入属性时遇到问题。
我的 applicationContext.xml 包含类似这样的内容:

<context:annotation-config />
<context:component-scan base-package="life" />
<util:properties id="config" location="classpath:config/files/config.properties"/>

例如,我想在 config.properties 文件中获取布尔值:

package life.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class LifePath {

    private @Value("#{config.production_mode}")static boolean prodMode;

我没有错误,但这不起作用。
如果有人有想法可以帮助我,那就太好了。

约翰

【问题讨论】:

    标签: spring properties


    【解决方案1】:

    这可能是因为prodModestatic。我不认为 Spring 会注意这一点,它只会连接实例字段。

    【讨论】:

      猜你喜欢
      • 2011-01-02
      • 1970-01-01
      • 2012-08-04
      • 2017-10-10
      • 2013-05-15
      • 1970-01-01
      • 2011-10-23
      • 2011-09-19
      • 1970-01-01
      相关资源
      最近更新 更多