Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java @spring中的值返回null_Java_Spring_Model View Controller_Null - Fatal编程技术网

Java @spring中的值返回null

Java @spring中的值返回null,java,spring,model-view-controller,null,Java,Spring,Model View Controller,Null,我在spring中使用@value将属性中的值加载到java常量中 但是我在常量中得到null值。帮帮我 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.

我在spring中使用@value将属性中的值加载到java常量中

但是我在常量中得到null值。帮帮我

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                               http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
                               http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
                               http://www.springframework.org/schema/mvc
                               http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                               http://www.springframework.org/schema/util 
                               http://www.springframework.org/schema/util/spring-util-3.0.xsd" >

    <context:component-scan base-package="com.epro.aemcrmsync" />

    <context:annotation-config />

    <context:property-placeholder location="classpath:com/epro/aemcrmsync/properties/config.properties" />

</beans>


Spring不处理
静态成员。将该字段设置为实例字段。将
ConfigConstants
bean插入需要使用它的任何位置。

Spring不处理
静态成员。将该字段设置为实例字段。将
ConfigConstants
bean插入需要使用它的任何位置。

此外,问题中的SpEL不好。仍然为nullonly@sridhar编辑您的问题并向我们展示如何使用bean.package com.epro.aemcrmsync.constants;导入org.springframework.beans.factory.annotation.Value;导入org.springframework.stereotype.Component@组件(“configConstants”)公共类configConstants{/@Value(“{config['aem_field_name']}”)@Value(${aem_field_name}”)公共字符串aem_USER_ID;}这是我的服务类@组件(value=“userService”)@Path(“user”)公共类userService{@Autowired private ConfigConstants ConfigConstants;此外,问题中的SpEL是错误的。仍然获取nullonly@sridhar编辑您的问题并向我们展示如何使用bean.package com.epro.aemcrmsync.constants;导入org.springframework.beans.factory.annotation.Value;导入org.springframework.stereotype.Component;@Component(“configConstants”)公共类configConstants{/@Value(“${config['aem_field_name']}”)@Value(${aem_field_name}”)公共字符串aem_USER_ID;}这是我的服务类..@Component(Value=“userService”)@Path(“USER”)公共类userService{@Autowired private ConfigConstants ConfigConstants;如回答中所述,您不能使用静态字段,其次您应该使用
@Value(${field\u name}”)
而不是
@Value($(field\u name}”)
。仍然只有null。我在使用jersey实现,这可能是个问题,对吗?即使我为xml注入了值,但它不起作用。还有一件事是我没有在xml中添加dispatcherservlet,是否有问题。帮我解决。我没有使用jersey,所以我不知道会出现什么问题。Anks mates的问题是如何解决的e it?也许你应该回答你自己的问题正如答案中所指出的,你不能使用静态字段,其次你应该使用
@Value(${field\u name}”)
而不是
@Value($(field\u name}”)
。仍然只有null。我在使用jersey实现,这可能是个问题,对吗?即使我为xml注入了值,但它不起作用。还有一件事是我没有在xml中添加dispatcherservlet,是否有问题。帮我解决。我没有使用jersey,所以我不知道会出现什么问题。Anks mates的问题是如何解决的是吗?也许你应该回答你自己的问题
package com.epro.aemcrmsync.constants;

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


@Component
public class ConfigConstants {


     @Value("$(field_name}")
    public static String USER_ID;

}