Unable to get Cassandra to Work in Basic Applcation

我们两清 提交于 2019-12-23 05:09:43

问题


This is my current error:

com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1 (com.datastax.driver.core.TransportException: [/127.0.0.1] Unexpected exception triggered (java.lang.NoClassDefFoundError: Could not initialize class com.datastax.driver.core.Codec)))
    com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:186)
    com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:81)
    com.datastax.driver.core.Cluster$Manager.init(Cluster.java:773)
    com.datastax.driver.core.Cluster$Manager.access$100(Cluster.java:706)
    com.datastax.driver.core.Cluster.<init>(Cluster.java:79)
    com.datastax.driver.core.Cluster.<init>(Cluster.java:66)
    com.datastax.driver.core.Cluster$Builder.build(Cluster.java:687)
    com.t2.claims.persistence.CassandraClient.getOrCreateCluster(CassandraClient.java:12)
    com.t2.claims.persistence.CassandraClient.getOrCreateSession(CassandraClient.java:18)
    com.t2.claims.dao.AlertDaoImpl.findAll(AlertDaoImpl.java:25)
    com.t2.claims.controllers.AlertIndexController.doAfterCompose(AlertIndexController.java:36)
    org.zkoss.zk.ui.impl.UiEngineImpl.doAfterCompose(UiEngineImpl.java:529)
    ....

I feel like I'm importing every artefact available im my pom.xml that I need to (as well as many I don't to try to get over this issue).

I just cannot understand why this does not work?

Here's my pom.xml for completeness:

<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.t2.claims</groupId>
<artifactId>T2ClaimsPortal</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>T2ClaimsPortal</name>

<properties>
    <spring.version>3.2.0.RELEASE</spring.version>
    <zk.version>6.0.2.1</zk.version>
    <commons-lang.version>2.4</commons-lang.version>
    <commons-fileupload.version>1.2.1</commons-fileupload.version>
    <commons-io.version>1.3.1</commons-io.version>
    <commons-logging.version>1.1.1</commons-logging.version>
</properties>

<repositories>
    <repository>
        <id>spring-milestone</id>
        <name>Spring Maven MILESTONE Repository</name>
        <url>http://maven.springframework.org/milestone</url>
    </repository>

    <repository>
        <id>ZK EE</id>
        <url>https://maven.zkoss.org/repo/zk/ee/</url>
    </repository>
</repositories>


<dependencies>

    <!-- Hector -->

    <dependency>
        <groupId>me.prettyprint</groupId>
        <artifactId>hector-core</artifactId>
        <version>0.8.0-2</version>
    </dependency>

    <!-- cassandra -->

    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-core</artifactId>
        <version>1.0.4</version>
    </dependency>

    <!-- cassandra dependencies -->

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.5.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.5</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>14.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.yammer.metrics</groupId>
        <artifactId>metrics-core</artifactId>
        <version>2.2.0</version>
    </dependency>
    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty</artifactId>
        <version>3.7.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cassandra</groupId>
        <artifactId>cassandra-all</artifactId>
        <version>1.2.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.thrift</groupId>
        <artifactId>libthrift</artifactId>
        <version>0.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.9.2</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.1</version>
    </dependency>

    <!-- spring framework -->

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc-portlet</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-core</artifactId>
        <version>2.2.6.RELEASE</version>
    </dependency>

    <!-- ZK -->

    <dependency>
        <groupId>org.zkoss.zk</groupId>
        <artifactId>zkplus</artifactId>
        <version>${zk.version}</version>
    </dependency>
    <dependency>
        <groupId>org.zkoss.zk</groupId>
        <artifactId>zkspring-core</artifactId>
        <version>3.1</version>
    </dependency>
    <dependency>
        <groupId>org.zkoss.theme</groupId>
        <artifactId>sapphire</artifactId>
        <version>${zk.version}</version>
    </dependency>
    <dependency>
        <groupId>org.zkoss.zk</groupId>
        <artifactId>zul</artifactId>
        <version>${zk.version}</version>
    </dependency>
    <dependency>
        <groupId>org.zkoss.common</groupId>
        <artifactId>zcommon</artifactId>
        <version>${zk.version}</version>
    </dependency>
    <dependency>
        <groupId>org.zkoss.zk</groupId>
        <artifactId>zk</artifactId>
        <version>${zk.version}</version>
    </dependency>
    <dependency>
        <groupId>org.zkoss.common</groupId>
        <artifactId>zweb</artifactId>
        <version>${zk.version}</version>
    </dependency>

    <!-- ZK dependencies -->

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>${commons-logging.version}</version>
    </dependency>
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>${commons-fileupload.version}</version>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>${commons-lang.version}</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>${commons-io.version}</version>
    </dependency>
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>
    <dependency>
        <groupId>commons-configuration</groupId>
        <artifactId>commons-configuration</artifactId>
        <version>1.6</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

    <!-- javax servlet -->

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>

    <!-- ***************************************************************************** -->
    <!-- ************************** JACKSON ****************************************** -->
    <!-- ***************************************************************************** -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.10</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.0.2</version>
    </dependency>

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.1</version>
    </dependency>


    <dependency>
        <groupId>org.jgroups</groupId>
        <artifactId>jgroups</artifactId>
        <version>3.2.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-math</artifactId>
        <version>2.0</version>
    </dependency>

    <!-- test -->

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.openjpa</groupId>
        <artifactId>openjpa</artifactId>
        <version>2.2.0</version>
    </dependency>

    <dependency>
        <groupId>org.hectorclient</groupId>
        <artifactId>hector-core</artifactId>
        <version>1.1-4</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-core</artifactId>
        <version>1.0.4</version>
    </dependency>

    <dependency>
        <groupId>org.hectorclient</groupId>
        <artifactId>hector-object-mapper</artifactId>
        <version>3.1-09</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.8</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>fluent-hc</artifactId>
        <version>4.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.2</version>
    </dependency>

    <dependency>
        <groupId>org.jboss.netty</groupId>
        <artifactId>netty</artifactId>
        <version>3.2.9.Final</version>
    </dependency>
    <dependency>
        <groupId>org.apache.curator</groupId>
        <artifactId>curator-recipes</artifactId>
        <version>2.2.0-incubating</version>
    </dependency>
</dependencies>

<build>
    <finalName>T2ClaimsPortal</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <includes>
                    <include>**/*Tests.java</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

Can someone provide me some understanding why I would get this exception? I have a cassandra client running locally. (version 1.2.11).


回答1:


This is not a problem of your pom file. Your client (DataStax Java driver) can not reach your cassandra database. It could be because of a few reasons:

  • Check the address of the node that your are using.
  • Check also the port, the default port for Cassandra native binary protocol is 9042.

More Information here: http://www.datastax.com/documentation/developer/java-driver/1.0/webhelp/index.html#java-driver/quick_start/qsSimpleClientCreate_t.html




回答2:


I installed Cassandra Server at a Virtual Machine, and I could not access it remotely. I obtained the exception:

com.datastax.driver.core.exceptions.NoHostAvailableException: 
All host(s) tried for query failed (tried: /192.168.1.76:9042 (com.datastax.driver.core.TransportException: [/192.168.1.76:9042] Cannot connect))

First, I confirmed I could not access to port 9042 through telnet.

I solved the issue modifying cassandra.yaml configuration file at Cassandra Server, with

rpc_address = 0.0.0.0
broadcast_rpc_address = 1.2.3.4

That is because

rpc_address (or rpc_interface) is used for client connections, listen_address property is for inter-node communication.




回答3:


it seems your cassandara server is not listening your request. try telnet 127.0.0.1 9160

and if you are getting this telnet: Unable to connect to remote host: Connection refused for jdbc library use DataStax driver,it is more mature and bug free

<dependency>
<groupId>org.apache-extras.cassandra-jdbc</groupId>
<artifactId>cassandra-jdbc</artifactId>
<version>1.2.5</version>
</dependency>

and restart your cassandara




回答4:


Got too similar problem: my spring app failed with NoHostAvailable and I was able to sort it out by setting both the rpc_port and native_transport_port in config file cassandra.yaml to match the eaxct IP address used for connecting to cassandra (i.e. Cluster.builder().addContactPoints(... the IP address here ...) ), but then it was cqlsh which no longer started because host not listening...until I realized that the listeners (rpc or native transport) are either listening on 127.0.0.1, else the true IP 10.0.0.5 of the host, and that makes a hell of a difference in this implementation! So I solved it by aligning the cqlsh script to also use 10.0.0.5 and getting rif of localhost name that resolve to 127.0.0.1 instead of 10.0.0.5... this is not compliant with the original IP networking principles to have an end app making such a difference.



来源:https://stackoverflow.com/questions/19538585/unable-to-get-cassandra-to-work-in-basic-applcation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!