spring Xml配置枚举

Posted by hcy on May 8, 2020

​ 在spring的配置文件中配置bean很简单,但某个bean中字段是枚举类型,如何注入呢。

1
2
3
4
5
6
7
8
9
10
11
12
13
    <bean id="jacksonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="objectMapper">
            <bean class="com.fasterxml.jackson.databind.ObjectMapper">
                <!--值为null时不返回-->
                <property name="serializationInclusion">
                    <util:constant static-field="com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL"/>
                </property>
            </bean>
        </property>
    </bean>

上面的com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL就是枚举类型,可以使用这种方式注入。


转载请注明出处:https://www.huangchaoyu.com/2020/05/08/spring-Xml配置枚举/