添加到Amir Jamak的答案中,你不必创建自定义HandlerInstantiator,因为Spring已经有了它,即SpringHandlerInstantiator。
你需要做的是将其连接到Spring配置中的Jackson2ObjectMapperBuilder。
@Beanpublic HandlerInstantiator handlerInstantiator(ApplicationContext applicationContext) { return new SpringHandlerInstantiator(applicationContext.getAutowireCapableBeanFactory());}@Beanpublic Jackson2ObjectMapperBuilder objectMapperBuilder(HandlerInstantiator handlerInstantiator) { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); builder.handlerInstantiator(handlerInstantiator); return builder;}


