봄에서 @value를 사용하여 속성에서 Java java 상수로 값을로드했습니다.@Value in spring returns
그러나 상수의 값으로 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>
등급 : static
구성원을 처리하지 않습니다
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;
}
답변에서 언급했듯이 정적 필드를 사용할 수없고 둘째로 @Value ("$ (field_name)") 대신'@Value ("$ {field_name}")'을 사용해야합니다. – geoand
여전히 null만을 받고 있습니다. 저지 구현을 사용하는 것은 문제가 될 것 같습니까? 심지어 xml에 값을 주입했지만 작동하지 않는 것은 xml에 dispatcherservlet을 추가하지 않은 것입니다. prob가 나를 도와 주는지 여부 – sridhar
저지를 사용하지 않았으므로 문제가 무엇인지 모르겠다 – geoand