spring数据json populator失败了

时间:2017-07-18 08:06:36

标签: json spring-data

我有一个 test.json 文件,如下所示

[{"_class":"com.abc.Xyz",  
  "uid":1,  
  "name":"first"  
 }, {  
  "uid":2,  
  "name":"second"  
}]

在资源目录下,配置类如下所示

@Configuration
class ApplicationConfig {

    @Bean
    public Jackson2RepositoryPopulatorFactoryBean repositoryPopulator() {

        Resource sourceData = new ClassPathResource("test.json");

        Jackson2RepositoryPopulatorFactoryBean factory = new Jackson2RepositoryPopulatorFactoryBean();

        factory.setResources(new Resource[] { sourceData });
        return factory;
    }
}

代码运行时,我遇到如下例外

    Caused by: java.lang.IllegalArgumentException: Name must not be null
at org.springframework.util.Assert.notNull(Assert.java:134) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.util.ClassUtils.forName(ClassUtils.java:214) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:284) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.data.repository.init.Jackson2ResourceReader.readSingle(Jackson2ResourceReader.java:113) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.repository.init.Jackson2ResourceReader.readFrom(Jackson2ResourceReader.java:92) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.repository.init.ResourceReaderRepositoryPopulator.readObjectFrom(ResourceReaderRepositoryPopulator.java:146) ~[spring-data-commons-1.13.4.RELEASE.jar:na]

任何提示?

1 个答案:

答案 0 :(得分:0)

抱歉,我的ide在json文件的末尾生成了一个空白字段。删除后,一切顺利