У меня есть приложение Spring Boot (2.0.3), которое выдает ошибку циклической ссылки, связанную с objectMapper (fast.xml реализация Jackson, 2.9.6). Он прекрасно работает с Gradle (4.10.2), но при развертывании выдает следующую ошибку:
...; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.leroyjenkins.service.common.config.CommonConfig':
Unsatisfied dependency expressed through field 'objectMappers'; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'objectMapper' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [com.fasterxml.jackson.databind.ObjectMapper]:
Circular reference involving containing bean 'org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration' -
consider declaring the factory method as static for independence from its containing instance. Factory method 'objectMapper' threw exception; nested exception is java.lang.NullPointerException",
"\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)",
CommonConfig ссылается на файл конфигурации, который у меня есть:
@Configuration
@EnableHypermediaSupport(type = .
EnableHypermediaSupport.HypermediaType.HAL)
@EnableScheduling
@Order(Ordered.LOWEST_PRECEDENCE)
@CompileStatic
@Slf4j
@Slf4jPlusMetrics("mlog")
class CommonConfig {
...
@Autowired List<ObjectMapper> objectMappers
@PostConstruct
void afterPropertiesSet() {
log.info("initializing CommonConfig objectMappersSize={},contextPath={},threadPoolSize={},threadPoolQueueCapacity={},threadPoolDefaultTimeout={},appName={}",
objectMappers.size(), contextPath, threadPoolSize, threadPoolQueueCapacity, threadPoolDefaultTimeout, appName)
objectMappers.each { ObjectMapper objectMapper ->
objectMapper.enable(SerializationFeature.INDENT_OUTPUT)
objectMapper.registerModule(new ParameterNamesModule())
objectMapper.registerModule(new Jdk8Module())
objectMapper.registerModule(new JavaTimeModule())
objectMapper.registerModule(new JodaModule())
objectMapper.registerModule(new GsnModelJacksonModule())
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
}
}
...
}
Мы только что обновились до jdk11 ... не уверен, что это актуально здесь.