【发布时间】:2016-06-21 05:13:06
【问题描述】:
我尝试使用 Cassandra 数据库在 STS 中创建一个 Spring MVC 项目。我是使用 Cassandra DB for Spring MVC 的新手。 我收到了这个错误:
java.lang.ClassNotFoundException: Could not load requested class : data.cassandra.CassandraDriver
org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:296)
我在我的 POM 中添加了 Cassandra Driver 的依赖项
这是我的 Pom 的一部分 org.hibernate.ogm 休眠-ogm-cassandra 5.0.0.Final
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-cassandra -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.datastax.cassandra/cassandra-driver-core -->
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.0.2</version>
</dependency>
这是我的Hibernate.cfg.xml
<session-factory>
<property name="hibernate.connection.driver_class">
cdata.cassandra.CassandraDriver
</property>
<property name="hibernate.connection.url">
jdbc:cassandra:Database=libran;Port=9042;Server=127.0.0.1
</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="show_sql">true</property>
<mapping class="com.personal.myTrialApp.model.Link"></mapping>
这是我的休眠工具
private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;
static
{
try
{
Configuration configuration = new Configuration().configure();
serviceRegistry = new ServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.buildServiceRegistry();
sessionFactory = configuration
.buildSessionFactory(serviceRegistry);
}
catch (HibernateException he)
{
System.err.println("Error creating Session: " + he);
throw new ExceptionInInitializerError(he);
}
}
public static SessionFactory getSessionFactory()
{
return sessionFactory;
}
这是我的表对象link
@Table("link")
public class Link
{
@PrimaryKey
private Integer linkID;
private String name;
private String address;
// getter and setter
}
这是我的LinkDao
public class LinkDao
{
public static List<Link> getLink()
{
Session session = HibernateUtil.getSessionFactory().openSession();
List<Link> links = session.createQuery("from Link").list();
return links;
}
}
我想从数据库中获取有关链接 ID、名称和地址的数据,但我收到了那个错误。我希望我不要重新发布,有人可以帮助我吗?
谢谢
【问题讨论】:
标签: java spring hibernate maven spring-mvc