无法将JavaTimeModule导入Spring Boot配置类

时间:2017-11-09 11:04:45

标签: java spring gradle

当我尝试导入import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

这是我的班级:

package com.linkedin.learning.linkedinfullstackappangularspringboot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;


@Configuration
public class ApiConfig {

@Bean
public ObjectMapper objectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JavaTimeModule());

    return new ObjectMapper();
}

@Bean
public ObjectWriter objectWriter(ObjectMapper objectMapper) {
    return objectMapper.writerWithDefaultPrettyPrinter();
}

不导入。在我的build.gradle文件中,我有以下内容:

// https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.2'

该项目成功建立,但我仍然无法将其导入我的班级。我该怎么办?

1 个答案:

答案 0 :(得分:2)

尝试更新Gradle项目一次,应该再次下载依赖项。 否则,请单独下载jar并将其作为依赖项手动包含在项目中。