我在jackson对象映射器上为自定义日期制作了这个类:
公共类CustomObjectMapper扩展了ObjectMapper {
@Value("#{cfgproperties.dateformat}")
private String dateFormats;
public CustomObjectMapper() throws Exception{
super.configure(Feature.WRITE_DATES_AS_TIMESTAMPS, false);
SimpleDateFormat dateFormat = new SimpleDateFormat(dateFormats); //is empty
setDateFormat(dateFormat);
}
}
我的servlet.xml是:
<util:properties id="cfgproperties" location="classpath:cfg.properties" />
<context:component-scan base-package="com.controller" />
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper">
<bean class="com.controller.CustomObjectMapper" />
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
这不起作用,因为变量@Value(“#{cfgproperties.dateformat}”)dateFormats为null, 怎么解决?感谢。