0

我正在尝试启动 apache camel 以进行集成,你能告诉我需要为骆驼配置做什么吗?运行这个类

运行类错误

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.apache.camel.support.ServiceSupport.<clinit>(ServiceSupport.java:39)
    at MainExample.boot(MainExample.java:21)
    at MainExample.main(MainExample.java:16)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader$1.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)
    ... 3 more

我们使用camel-core-2.11.0.jar

这是我的课

MainExample.java

import java.util.Date;

import javax.annotation.processing.Processor;

import org.apache.camel.Exchange;
import org.apache.camel.Main;
import org.apache.camel.builder.RouteBuilder;

@SuppressWarnings("deprecation")
public class MainExample {

    private Main main;

    public static void main(String[] args) throws Exception {
        MainExample example = new MainExample();
        example.boot();
    }

    public void boot() throws Exception {
        // create a Main instance
        main = new Main();
        // enable hangup support so you can press ctrl + c to terminate the JVM
        main.enableHangupSupport();
        // bind MyBean into the registery
        main.bind("foo", new MyBean());
        // add routes
        main.addRouteBuilder(new MyRouteBuilder());

        // run until you terminate the JVM
        System.out.println("Starting Camel. Use ctrl + c to terminate the JVM.\n");
        main.run();
    }

    private static class MyRouteBuilder extends RouteBuilder {
        @Override
        public void configure() throws Exception {
            from("timer:foo?delay=2000")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("Invoked timer at " + new Date());
                    }
                })
                .beanRef("foo");
        }
    }

    public static class MyBean {
        public void callMe() {
            System.out.println("MyBean.calleMe method has been called");
        }
    }
}
4

1 回答 1

0

只需将 SLF4J 库添加到您的 CLASSPATH。通常你需要 SLF4J API (slf4j-api-version.jar) 和一个实现,例如 slf4j-log4j-version.jar

于 2013-04-26T07:53:01.957 回答