java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException while connecting Cassandra DB
java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException while connecting Cassandra DB
我正在尝试通过 Java 与我的 Cassandra 实例建立简单的连接。我为 cqlsh 创建了一个 'demo' 键空间,并在 java 程序中创建了一个 table。代码如下:
使用的罐子:
- slf4j.api-1.6.1
cassandra-all-2.1.2
public class CassandraConnection {
public static void main(String[] args){
String ipAddress="127.0.0.1";
String keySpace="demo";
Cluster cluster;
Session session;
cluster=Cluster.builder().addContactPoint(ipAddress).build();
session=cluster.connect(keySpace);
System.out.println("====================Before insert");
String cqlInsertStmt="insert into users (lastname,age,city,email,firstname) values"
+"('Gopalan',32,'Paramakkudi','murugan@gmail.com','Murugan') ";
session.execute(cqlInsertStmt);
String cqlSelectStmt="select * from users";
ResultSet resultSet=session.execute(cqlSelectStmt);
System.out.println("=================After insert");
for(Row row: resultSet){
System.out.format("%s %s %d %s %s \n", row.getString("firstname"),row.getString("lastname"),row.getInt("age"),row.getString("city"),row.getString("email"));
}
System.out.println("=================After update");
}
}
我收到以下错误:
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at com.datastax.driver.core.Cluster.<clinit>(Cluster.java:60)
at CassandraConnection.main(CassandraConnection.java:21)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException
at java.net.URLClassLoader.run(Unknown Source)
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at com.datastax.driver.core.Cluster.<clinit>(Cluster.java:60)
at CassandraConnection.main(CassandraConnection.java:21)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException
at java.net.URLClassLoader.run(Unknown Source)
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
您必须确保 logback JAR 在您的类路径中。
请参阅 here for starters; and beyond that; the real take-away here: the runtime is telling you that it can't find a certain class; and it gives you the full name of that class. Or you look here 了解 Cassandra 对 logback 的看法。
你接受那个输入;然后你转向你最喜欢的搜索引擎来弄清楚发生了什么。
此问题的根本原因是所需的 jars 在 CLASSPATH 中不可用。请添加以下依赖项 - 它们将解决您的问题。
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
我正在尝试通过 Java 与我的 Cassandra 实例建立简单的连接。我为 cqlsh 创建了一个 'demo' 键空间,并在 java 程序中创建了一个 table。代码如下:
使用的罐子:
- slf4j.api-1.6.1
cassandra-all-2.1.2
public class CassandraConnection { public static void main(String[] args){ String ipAddress="127.0.0.1"; String keySpace="demo"; Cluster cluster; Session session; cluster=Cluster.builder().addContactPoint(ipAddress).build(); session=cluster.connect(keySpace); System.out.println("====================Before insert"); String cqlInsertStmt="insert into users (lastname,age,city,email,firstname) values" +"('Gopalan',32,'Paramakkudi','murugan@gmail.com','Murugan') "; session.execute(cqlInsertStmt); String cqlSelectStmt="select * from users"; ResultSet resultSet=session.execute(cqlSelectStmt); System.out.println("=================After insert"); for(Row row: resultSet){ System.out.format("%s %s %d %s %s \n", row.getString("firstname"),row.getString("lastname"),row.getInt("age"),row.getString("city"),row.getString("email")); } System.out.println("=================After update"); } }
我收到以下错误:
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at com.datastax.driver.core.Cluster.<clinit>(Cluster.java:60)
at CassandraConnection.main(CassandraConnection.java:21)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException
at java.net.URLClassLoader.run(Unknown Source)
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at com.datastax.driver.core.Cluster.<clinit>(Cluster.java:60)
at CassandraConnection.main(CassandraConnection.java:21)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException
at java.net.URLClassLoader.run(Unknown Source)
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
您必须确保 logback JAR 在您的类路径中。
请参阅 here for starters; and beyond that; the real take-away here: the runtime is telling you that it can't find a certain class; and it gives you the full name of that class. Or you look here 了解 Cassandra 对 logback 的看法。
你接受那个输入;然后你转向你最喜欢的搜索引擎来弄清楚发生了什么。
此问题的根本原因是所需的 jars 在 CLASSPATH 中不可用。请添加以下依赖项 - 它们将解决您的问题。
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>