java.lang.NoClassDefFoundError:连接Cassandra DB时ch/qos/logback/core/joran/spi/JoranException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42205247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:59:11  来源:igfitidea点击:

java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException while connecting Cassandra DB

javacassandradatastax

提问by Anand Kumar

I was trying out a simple connection to my Cassandra instance through Java. I made a 'demo' keyspace to cqlsh and created a table in the java program. The code is below:

我正在尝试通过 Java 与我的 Cassandra 实例建立一个简单的连接。我为 cqlsh 创建了一个“演示”键空间,并在 java 程序中创建了一个表。代码如下:

Jars Used:

使用的罐子:

  • 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','[email protected]','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");
    
        }
    }
    
  • 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','[email protected]','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");
    
        }
    }
    

I am getting the following error:

我收到以下错误:

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

采纳答案by GhostCat

You have to make sure that the logbackJAR is within your classpath.

您必须确保logbackJAR 在您的类路径中。

See herefor 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 fullname of that class. Or you look hereto read what Cassandra has to say about logback.

初学者请看这里;除此之外;真正的要点是:运行时告诉您它找不到某个类;它会为您提供该类的名。或者您可以在这里阅读 Cassandra 对 logback 的看法。

You take that input; and then you turn to your favorite search engine in order to figure what is going on.

你接受那个输入;然后你转向你最喜欢的搜索引擎,以了解正在发生的事情。

回答by Rajeev Rathor

The root cause of this issue is the required jars not being available in the CLASSPATH. Please add the following dependencies - they will solve your issue.

此问题的根本原因是 CLASSPATH 中没有所需的 jar。请添加以下依赖项 - 它们将解决您的问题。

<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>