Hector connects to Cassandra

im trying to connect cassandra using Hector:

public class Main { public static void main(String[] args) { StringSerializer stringSerializer = StringSerializer.get(); Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", "localhost:9160"); Keyspace keyspace = HFactory.createKeyspace("Keyspace1", cluster); Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer); mutator.insert("jsmith", "Standard1", HFactory.createStringColumn("first", "John")); } } 

Problem:

 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:230) at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:112) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:275) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:248) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:261) at me.prettyprint.cassandra.service.AbstractCluster.<init>(AbstractCluster.java:43) at me.prettyprint.cassandra.service.AbstractCluster.<init>(AbstractCluster.java:57) at me.prettyprint.cassandra.service.ThriftCluster.<init>(ThriftCluster.java:17) at me.prettyprint.hector.api.factory.HFactory.createCluster(HFactory.java:112) at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:104) at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:96) at javaapplication1.Main.main(Main.java:25) Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder at java.net.URLClassLoader$1.run(URLClassLoader.java:276) at java.net.URLClassLoader$1.run(URLClassLoader.java:265) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:264) at java.lang.ClassLoader.loadClass(ClassLoader.java:325) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:270) ... 13 more Java Result: 1 

How can i decide?

I until the last patience with hector and cassandra, I tried to connect and could not. I run the twissjava sample and it works, but when I extend the main class to make my own test, it does not start.

+4
source share
3 answers

This issue is "documented in the wiki on the " SLF4J in the Hector "page

Short version: you need to add a library that implements the SLF4J api.

+3
source

What development environment are you using?

I had the same problem in netbeans. Here are the files you need (but be careful about the versions you use).

log4j download: http://www.findjar.com/jar/log4j/log4j/1.2.11/log4j-1.2.11.jar.html slf4j download: http://www.findjar.com/jar/de/huxhorn /lilith/de.huxhorn.lilith.slf4j/0.9.35/de.huxhorn.lilith.slf4j-0.9.35.jar.html

ps find the findjar website for the correct versions if these do not work, but I use the two with cassandra 1.0.7 and hector 1.0.2 and they worked for me.

+2
source

you need to add Hector dependencies like SLF4j, Log4j to your classpath, then your problem will be solved. You have exactly the same problem for you, and my problem is resolved. Correct my English ..: D

+1
source

Source: https://habr.com/ru/post/1341066/


All Articles