【问题标题】:Spring Web MVC Environment @Autowired To Get Only System Property throws NullPointerExceptionSpring Web MVC环境@Autowired仅获取系统属性抛出NullPointerException
【发布时间】:2014-12-10 06:23:26
【问题描述】:

我正在使用Spring 4.1.1.RELEASE,我得到了 NO 属性文件,以防万一我想通过 System.setProperty() 设置一些运行时变量,然后通过 Spring 通过环境变量获取它,但是它说环境变量是null。如下在我的@Component 类之一中,我使用了一个变量。在此之前,我从其他地方设置了系统属性。

@Autowired
private Environment environment;

【问题讨论】:

    标签: java spring spring-mvc properties environment-variables


    【解决方案1】:

    我遇到了同样的问题。
    implements EnvironmentAware 而不是使用@Autorwired 解决了我的问题。

    【讨论】:

    • 你能提供一个更完整的例子吗?
    猜你喜欢
    • 1970-01-01
    • 2018-11-12
    • 2017-06-06
    • 2015-03-16
    • 1970-01-01
    • 2018-07-15
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多