我是骆驼和蓝图的新手。
我正在尝试制作一个简单的程序将数据放入队列中。 不知道这里出了什么问题。
Camel Context file ==>
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="helloBean" class="com.camelSampleBundle.HelloBean">
<property name="say" value="Hi from Camel" />
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<camelContext id="blueprintContext" trace="false"
xmlns="http://camel.apache.org/schema/blueprint">
<route id="timerToLog">
<from uri="timer:foo?period=5000" />
<setBody>
<constant>Hello World!</constant>
</setBody>
<to uri="activemq:camel.q.timer" />
<log message="The message contains ${body}" />
</route>
<!-- <route id="anotherRoute">
<from uri="activemq:camel.q.timer" />
<log message="The message contains ${body}" />
<to uri="mock:result" />
</route> -->
</camelContext>
</blueprint>
的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.camelSampleBundle</groupId>
<artifactId>camel-sampleBundle</artifactId>
<packaging>bundle</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>Sample Bundle</name>
<url>http://www.myorganization.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<fuse.version>2.12.0.redhat-610379</fuse.version>
</properties>
<repositories>
<repository>
<id>release.fusesource.org</id>
<name>FuseSource Release Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>snapshot.fusesource.org</id>
<name>FuseSource Snapshot Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>release.fusesource.org</id>
<name>FuseSource Release Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>snapshot.fusesource.org</id>
<name>FuseSource Snapshot Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.10.0.redhat-60024</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-blueprint</artifactId>
<version>2.10.0.redhat-60024</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>2.10.0.redhat-60024</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.13.2</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- testing -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-blueprint</artifactId>
<version>2.10.0.redhat-60024</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- to generate the MANIFEST-FILE of the bundle -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>camel-sampleBundle</Bundle-SymbolicName>
<Import-Package>*</Import-Package>
<Export-Package />
</instructions>
</configuration>
</plugin>
<!-- to run the example using mvn camel:run -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>2.10.0.redhat-60024</version>
<configuration>
<useBlueprint>true</useBlueprint>
</configuration>
</plugin>
</plugins>
</build>
</project>
错误Stacktrace ==&gt;
org.osgi.service.blueprint.container.ComponentDefinitionException: 无法实例化组件 org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:671) 在 org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:370) 在 org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:261) 在 java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471) 在java.util.concurrent.FutureTask.run(FutureTask.java:262)at org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106) 在 org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48) 在 java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471) 在java.util.concurrent.FutureTask.run(FutureTask.java:262)at java.util.concurrent.ScheduledThreadPoolExecutor中的$ ScheduledFutureTask.access $ 201(ScheduledThreadPoolExecutor.java:178) 在 java.util.concurrent.ScheduledThreadPoolExecutor中的$ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 在 java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615) 在java.lang.Thread.run(Thread.java:745)引起: java.lang.NoClassDefFoundError:org / apache / camel / spi / EndpointCompleter at java.lang.ClassLoader.defineClass1(Native Method)at java.lang.ClassLoader.defineClass(ClassLoader.java:800)at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 在java.net.URLClassLoader.defineClass(URLClassLoader.java:449)at java.net.URLClassLoader.access $ 100(URLClassLoader.java:71)at java.net.URLClassLoader $ 1.run(URLClassLoader.java:361)at java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:354)at java.lang.ClassLoader.loadClass(ClassLoader.java:425)at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308)at at java.lang.ClassLoader.loadClass(ClassLoader.java:358)at de.kalpatec.pojosr.framework.PojoSRBundle.loadClass(PojoSRBundle.java:431) 在 org.apache.aries.blueprint.container.BlueprintContainerImpl.loadClass(BlueprintContainerImpl.java:419) 在 org.apache.aries.blueprint.container.BlueprintRepository.loadClass(BlueprintRepository.java:410) 在 org.apache.aries.blueprint.container.GenericType.parse(GenericType.java:113) 在 org.apache.aries.blueprint.di.AbstractRecipe.doLoadType(AbstractRecipe.java:168) 在 org.apache.aries.blueprint.di.AbstractRecipe.loadType(AbstractRecipe.java:161) 在 org.apache.aries.blueprint.container.BeanRecipe.loadClass(BeanRecipe.java:249) 在 org.apache.aries.blueprint.container.BeanRecipe.getType(BeanRecipe.java:895) 在 org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:323) 在 org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:806) 在 org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787) 在 org.apache.aries.blueprint.di.AbstractRecipe $ 1.call(AbstractRecipe.java:79) 在java.util.concurrent.FutureTask.run(FutureTask.java:262)at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88) 在 org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245) 在 org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183) 在 org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:667) ... 13更多引起:java.lang.ClassNotFoundException: org.apache.camel.spi.EndpointCompleter at java.net.URLClassLoader $ 1.run(URLClassLoader.java:366)at java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:354)at java.lang.ClassLoader.loadClass(ClassLoader.java:425)at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308)at at java.lang.ClassLoader.loadClass(ClassLoader.java:358)... 42更多
答案 0 :(得分:2)
问题在于驼峰版本。 我在我的pom.xml中更改了驼峰版本并且工作正常
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.12.0.redhat-610379</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-blueprint</artifactId>
<version>2.12.0.redhat-610379</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>2.12.0.redhat-610379</version>
</dependency>
答案 1 :(得分:1)
你的OSGI环境中是否安装了camel-core?如果您在karaf(2.x.x),请键入
功能:列表| grep camel
如果没有显示,您可以执行以下操作:
特色:选择骆驼
添加存储库,然后:
功能:安装camel-core
我强烈建议您阅读&#34; OSGi in Action&#34;。 ClassNotFoundException通常表示您的上下文没有对另一个包将导出的类具有可见性。自&#34; org / apache / camel / spi / EndpointCompleter&#34;是camel-core,你必须在你的osgi环境中安装它。
检查包是否已导出:
jschoreels@lab> exports | grep camel.spi
100 org.apache.camel.spi; version="2.14.3"
jschoreels@lab> list | grep 100
START LEVEL 100 , List Threshold: 50
[ 100] [Active ] [ ] [ ] [ 50] camel-core (2.14.3)
但是,您的捆绑包也必须导入此包。你可以做:
imports <bundleidOfYourImportingBundle>
并检查包裹是否在那里。
如果没有,您必须检查是否正确构建了捆绑包。正确的bundle应该在MANIFEST.MF中声明一些OSGi头。 You can have an example here
要使用maven生成它,您应该考虑使用依赖于bnd的maven bundle plugin。
以下是使用它的示例:
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven-bundle-pulgin.version}</version>
<configuration>
<instructions>
<Import-Package>*</Import-Package>
<Export-Package />
</instructions>
</configuration>
</plugin>
</plugins
</build>
如果您想学习OSGi,我建议您OSGi in action并至少阅读三个层(模块化,生命周期和服务)章节,以了解该发现的工作原理。它最后解释了什么是bnd以及如何使用它。
答案 2 :(得分:0)
stacktrace暗示您似乎在模拟的OSGi环境中运行您的驼峰上下文。
de.kalpatec.pojosr.framework.PojoSRBundle.loadClass(PojoSRBundle.java:431)
尝试在像karaf这样的真实OSGi环境中运行它。