我是Mule的新手,我正在尝试解决java类中的以下错误。
下面是我的java类:
package com.eb.mule;
import java.sql.Timestamp;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.exceptions.NoHostAvailableException;
import com.datastax.driver.core.utils.UUIDs;
public class CassandraInsert {
private static CassandraInsert _instance;
protected static Cluster cluster;
protected static Session session;
private String hostname = "My ip address";
private int port = myportnumber;
public static synchronized CassandraInsert getInstance() {
if (_instance == null) {
_instance = new CassandraInsert();
}
return _instance;
}
public CassandraInsert() {**
try{
cluster = Cluster.builder().addContactPoint(hostname).withPort(port).build();
session = cluster.connect();
} catch (NoHostAvailableException e) {
throw new RuntimeException(e);
}
System.out.println("connected to cluster");
}
public static Cluster getCluster() {
return cluster;
}
public static Session getSession() {
return session;
}
public String insertSensorData(Integer component, Integer measurement, Timestamp datetime, Double sensorvalue) {
//Builder builder = Cluster.builder();
//Cluster cluster = builder.addContactPoint("myipaddress").withPort(portnumber).build();
//Session session = cluster.connect();
StringBuilder insertString = new StringBuilder();
UUIDs uuid = new com.datastax.driver.core.utils.UUIDs();
insertString.append("insert into dm.data (component_id, measurement_id, snapshot, value) values(")
.append(component)
.append(", ")
.append(measurement)
.append(", ")
.append(uuid.startOf(datetime.getTime()))
.append(", '")
.append(sensorvalue)
.append("');");
ResultSet result;
try {
result = session.execute(insertString.toString());
} catch (Exception ex) {
ex.printStackTrace();
}
//session.shutdown();
//cluster.shutdown();
return "data loaded: measurement_id: " + measurement + " Component_id: " + component + " Snapshot: " + datetime + " Value: " + sensorvalue;
}
}
我的控制台显示以下错误...
Exception in thread "main" org.mule.module.launcher.DeploymentStartException: ClassNotFoundException: org.apache.cassandra.transport.FrameCompressor
at org.mule.module.launcher.application.DefaultMuleApplication.start(DefaultMuleApplication.java:170)
at org.mule.module.launcher.application.ApplicationWrapper.start(ApplicationWrapper.java:107)
at org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:48)
at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:127)
Caused by: org.mule.api.lifecycle.InitialisationException: Unable to create instance of POJO service
at org.mule.component.DefaultJavaComponent.doStart(DefaultJavaComponent.java:76)
at org.mule.component.AbstractComponent$4.onTransition(AbstractComponent.java:313)
at org.mule.component.AbstractComponent$4.onTransition(AbstractComponent.java:308)
at org.mule.lifecycle.AbstractLifecycleManager.invokePhase(AbstractLifecycleManager.java:141)
at org.mule.component.ComponentLifecycleManager.fireStartPhase(ComponentLifecycleManager.java:71)
at org.mule.component.AbstractComponent.start(AbstractComponent.java:307)
at org.mule.processor.chain.AbstractMessageProcessorChain.start(AbstractMessageProcessorChain.java:94)
at org.mule.routing.MessageProcessorFilterPair.start(MessageProcessorFilterPair.java:105)
at org.mule.routing.AbstractSelectiveRouter.start(AbstractSelectiveRouter.java:114)
at org.mule.processor.AbstractMuleObjectOwner.start(AbstractMuleObjectOwner.java:78)
at org.mule.processor.AbstractMuleObjectOwner.start(AbstractMuleObjectOwner.java:78)
at org.mule.processor.chain.AbstractMessageProcessorChain.start(AbstractMessageProcessorChain.java:94)
at org.mule.construct.AbstractFlowConstruct.startIfStartable(AbstractFlowConstruct.java:326)
at org.mule.construct.AbstractPipeline.doStart(AbstractPipeline.java:310)
at org.mule.construct.AbstractFlowConstruct$2.onTransition(AbstractFlowConstruct.java:145)
at org.mule.construct.AbstractFlowConstruct$2.onTransition(AbstractFlowConstruct.java:141)
at org.mule.lifecycle.AbstractLifecycleManager.invokePhase(AbstractLifecycleManager.java:141)
at org.mule.construct.FlowConstructLifecycleManager.fireStartPhase(FlowConstructLifecycleManager.java:95)
at org.mule.construct.AbstractFlowConstruct.start(AbstractFlowConstruct.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mule.lifecycle.phases.DefaultLifecyclePhase.applyLifecycle(DefaultLifecyclePhase.java:225)
at org.mule.lifecycle.RegistryLifecycleManager$RegistryLifecycleCallback.onTransition(RegistryLifecycleManager.java:276)
at org.mule.lifecycle.RegistryLifecycleManager.invokePhase(RegistryLifecycleManager.java:155)
at org.mule.lifecycle.RegistryLifecycleManager.fireLifecycle(RegistryLifecycleManager.java:126)
at org.mule.registry.AbstractRegistryBroker.fireLifecycle(AbstractRegistryBroker.java:80)
at org.mule.registry.MuleRegistryHelper.fireLifecycle(MuleRegistryHelper.java:120)
at org.mule.lifecycle.MuleContextLifecycleManager$MuleContextLifecycleCallback.onTransition(MuleContextLifecycleManager.java:94)
at org.mule.lifecycle.MuleContextLifecycleManager$MuleContextLifecycleCallback.onTransition(MuleContextLifecycleManager.java:90)
at org.mule.lifecycle.MuleContextLifecycleManager.invokePhase(MuleContextLifecycleManager.java:72)
at org.mule.lifecycle.MuleContextLifecycleManager.fireLifecycle(MuleContextLifecycleManager.java:64)
at org.mule.DefaultMuleContext.start(DefaultMuleContext.java:255)
at org.mule.module.launcher.application.DefaultMuleApplication.start(DefaultMuleApplication.java:147)
... 3 more
Caused by: org.mule.api.lifecycle.InitialisationException: null
at org.mule.object.SingletonObjectFactory.getInstance(SingletonObjectFactory.java:85)
at org.mule.component.AbstractJavaComponent.createLifecycleAdaptor(AbstractJavaComponent.java:112)
at org.mule.component.DefaultJavaComponent.doStart(DefaultJavaComponent.java:71)
... 37 more
Caused by: java.lang.NoClassDefFoundError: org/apache/cassandra/transport/FrameCompressor
at com.datastax.driver.core.Cluster$Builder.<init>(Cluster.java:288)
at com.datastax.driver.core.Cluster.builder(Cluster.java:107)
at com.eb.mule.CassandraInsert.<init>(CassandraInsert.java:29)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.mule.util.ClassUtils.instanciateClass(ClassUtils.java:412)
at org.mule.object.AbstractObjectFactory.getInstance(AbstractObjectFactory.java:136)
at org.mule.object.SingletonObjectFactory.getInstance(SingletonObjectFactory.java:81)
... 39 more
Caused by: java.lang.ClassNotFoundException: org.apache.cassandra.transport.FrameCompressor
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at org.mule.module.launcher.FineGrainedControlClassLoader.findClass(FineGrainedControlClassLoader.java:179)
at org.mule.module.launcher.MuleApplicationClassLoader.findClass(MuleApplicationClassLoader.java:144)
at org.mule.module.launcher.FineGrainedControlClassLoader.loadClass(FineGrainedControlClassLoader.java:123)
at org.mule.module.launcher.MuleApplicationClassLoader.loadClass(MuleApplicationClassLoader.java:150)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 49 more
我刚补充说: cassandra-driver-core-1.0.2 , MySQL 和 PostgreSQL jar文件。
答案 0 :(得分:1)
您缺少包含类FrameCompressor的依赖项/ jar。我认为这是cassandra-all
。