我在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>
班级:
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;
}
答案 0 :(得分:4)
Spring不会处理static
个成员。使该字段成为实例字段。在需要使用它的任何地方注入ConfigConstants
bean。