Java与MongoDB连接问题-获取SQL异常

时间:2019-06-14 02:18:15

标签: java mongodb spring-boot sqlexception

新功能在这里,第一篇文章...我正尝试使用Spring Boot连接到MongoDB,但得到sqlexception ...有什么建议吗?为什么在MongoDB配置中会出现SQL异常?

@Configuration
public class ApplicationConfig {



    @Bean
    --------public MongoItemReader<MongoDBEntity> reader() {
        System.out.println("REader");
        MongoItemReader<MongoDBEntity> reader = new ----------MongoItemReader<MongoDBEntity>();
        reader.setTemplate(mongoTemplate);
        reader.setQuery("{}");
        reader.setTargetType(MongoDBEntity.class);
        ---------reader.setTargetType((Class<? extends MongoDBEntity>) MongoDBEntity.class);
        reader.setSort(new HashMap<String, Sort.Direction>() {
            {
                put("_id", Direction.ASC);
            }
        });
        return reader;

    }

    @Bean
    public FlatFileItemWriter<MongoDBEntity> writer() {
        System.out.println("Writer");
        FlatFileItemWriter<MongoDBEntity> writer = new FlatFileItemWriter<MongoDBEntity>();
        writer.setResource(new FileSystemResource(
                "c://outputs//temp.all.csv"));
        writer.setLineAggregator(new DelimitedLineAggregator<MongoDBEntity>() {
            {
                setDelimiter(",");
                setFieldExtractor(new BeanWrapperFieldExtractor<MongoDBEntity>() {
                    {
                        setNames(new String[] { "id", "name" });
                    }
                });
            }
        });

        return writer;
    }

    @Bean
    public Step step1() {
        return stepBuilderFactory.get("step1")
                .<MongoDBEntity, MongoDBEntity> chunk(10).reader(reader())
                .writer(writer()).build();
    }

    @Bean
    public Job exportUserJob() {
        return jobBuilderFactory.get("exportUserJob")
                .incrementer(new RunIdIncrementer()).flow(step1()).end()
                .build();
    }

----------  @Bean
    public CustomConversions mongoCustomConversions() {
        return new CustomConversions(Collections.emptyList());
    }

}

有什么我想念的东西吗...为什么在Mongo中出现SQL异常?检查了pom文件...没有对Oracle等的引用...

1 个答案:

答案 0 :(得分:0)

谢谢大家..抱歉,我的错误是在创建文件时我使用了以前的pom文件,该文件具有一些参考。一次删除它们并安装正确版本的mongo jars即可解决此问题。

再次感谢..