当前位置: 首页 > 知识库问答 >
问题:

Spring Data Cassandra ClassNotFoundException

朱华皓
2023-03-14

启动spring boot application my spring boot application spring boot version 2.2.4和cassandra version spring-data-cassandra 3.0.1时出现此错误

Caused by: java.lang.ClassNotFoundException: org.springframework.data.convert.CustomConversions$ConverterConfiguration
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 113 common frames omitted
 public class CassandraConfig {
    @Bean
    public CqlSessionFactoryBean session() {

        CqlSessionFactoryBean session = new CqlSessionFactoryBean();
        session.setContactPoints("localhost");
        session.setKeyspaceName("mykeyspace");
        session.setUsername("cassandra");
        session.setPassword("cassandra");
        session.setLocalDatacenter("dc1");
        return session;
    }

    @Bean
    public SessionFactoryFactoryBean sessionFactory(CqlSession session, CassandraConverter converter) {

        SessionFactoryFactoryBean sessionFactory = new SessionFactoryFactoryBean();
        sessionFactory.setSession(session);
        sessionFactory.setConverter(converter);
        sessionFactory.setSchemaAction(SchemaAction.NONE);

        return sessionFactory;
    }

    @Bean
    public CassandraMappingContext mappingContext(CqlSession cqlSession) {

        CassandraMappingContext mappingContext = new CassandraMappingContext();
        mappingContext.setUserTypeResolver(new SimpleUserTypeResolver(cqlSession));

        return mappingContext;
    }

    @Bean
    public CassandraConverter converter(CassandraMappingContext mappingContext) {
        return new MappingCassandraConverter(mappingContext);
    }

    @Bean
    public CassandraOperations cassandraTemplate(SessionFactory sessionFactory, CassandraConverter converter) {
        return new CassandraTemplate(sessionFactory, converter);
    }

}

共有1个答案

杨乐意
2023-03-14

这些版本不兼容。spring-data-cassandra从2.2.x版本到3.x.x版本有重大的突破性变化。

要使用3.x.x版本的Cassandra,您需要将spring升级到2.3.x。或者,您需要将spring-data-cassandra降级到2.2.x版本。

 类似资料:

相关问答

相关文章

相关阅读