关键 Web 服务 Spring 错误

Pivotal Web Services Spring Error

当我将 Spring 应用程序上传到 Pivotal Web Services 时,出现两个错误:

ERR Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.http.converter.json.MappingJackson2HttpMessageConverter]: Factory 
method 'jacksonHttpMessageConverter' threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'objectMapper' defined in class path resource
[io/app/config/AppRestMvcConfiguration.class]: Bean instantiation via factory method 
failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to 
instantiate [com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'objectMapper' 
threw exception; nested exception is java.lang.NullPointerException

Failed to instantiate [org.springframework.http.converter.json.MappingJackson2HttpMessageCo
nverter]: Factory method 'halJacksonHttpMessageConverter' threw exception; nested 
exception is org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'halObjectMapper' defined in class path resource [io/papped/config/PappedRestMvcC
onfiguration.class]: Bean instantiation via factory method failed; nested exception is 
org.springframework.beans.BeanInstantiationException: Failed to instantiate 
[com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'halObjectMapper' threw 
exception; nested exception is java.lang.NullPointerException

所以基本上,它无法在我的配置 class 中初始化 objectMapper 和 halObjectMapper(这些在 SpringBootRepositoryRestMvcConfiguration class 中预定义)。当我 运行 在我的计算机上本地应用程序时,不会发生这些错误。

我已经尝试删除我的配置 class 但它仍然给出错误。我尝试使用以下代码手动实例化 objectMapper/halObjectMapper:

private final static ObjectMapper mapper = new ObjectMapper();

@Bean
@Primary
public com.fasterxml.jackson.databind.ObjectMapper objectMapper() {
    return mapper;
}

@Bean
@Primary
public ObjectMapper halObjectMapper() {
    return mapper;
}

这使得它 运行 在关键的网络服务上,但每当我尝试访问 MongoRepository 时都会出现堆栈溢出错误(我的模型中没有循环引用)。

如何解决?

问题是我为云设置 mongo 存储库服务的方式。使用以下代码使其工作:

@Configuration
@Profile("!local")
public class DatabaseConfiguration extends AbstractCloudConfig {
    @Bean
    public MongoDbFactory documentMongoDbFactory() {
        return connectionFactory().mongoDbFactory();
    }
}