2017-07-18 75 views
0

我有一個test.json文件作爲波紋管春天數據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] 

任何提示?

+0

我的ide在json文件的末尾生成一個空白項目。刪除它可以解決問題 – yk42b

回答

0

對不起,我的IDE在JSON文件的末尾產生一個空白領域。刪除它後,一切都很好