我有一个使用ApacheCamel集成主机的Spring Boot 应用程序app.jar
,XML路由和自定义Camel JAVA类我的要求是将XML路由和自定义camel处理器移到Spring Boot jar之外,以便在部署期间用户可以编写自己的自定义XML路由和处理器。我能够使用camel.springboot.routes-include-pattern = file:${workdir.path}/camel/routes/*.xml
将XML路由外部化并且我在workdir/camel/libs/
内创建了一个jar(使用gradle java-libray插件),其中包含了所有必需的自定义camel JAVA类。
package com.example;
import org.apache.camel.AggregationStrategy;
import org.apache.camel.Exchange;
import org.springframework.stereotype.Component;
import com.dependencies.from.other.springboot.application.XYZ;
@Component
public class GenericParallelApiAggregationStrategy implements AggregationStrategy {
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
//Business logic here
}
}
现在,我尝试通过在spring boot类路径中添加上述jar来运行spring Boot 项目,如下所示:
java -Dworkdir.path=D:/sample/workdir -cp "D:/sample/app.jar;D:/sample/workdir/camel/libs/*" org.springframework.boot.loader.JarLauncher
这是我得到的错误:
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.example.GenericParallelApiAggregationStrategy] for bean with name 'genericParallelApiAggregationStrategy' defined in URL [jar:file:/D:/sample/workdir/libs/camel-sample.jar!/com/example/GenericParallelApiAggregationStrategy.class]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/apache/camel/AggregationStrategy
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:686)
... 27 more
Caused by: java.lang.NoClassDefFoundError: org/apache/camel/AggregationStrategy
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
... 38 more
Caused by: java.lang.ClassNotFoundException: org.apache.camel.AggregationStrategy
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 58 more
这是sample-camel项目的build.gradle
文件:
plugins {
id 'java-library'
}
sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot:2.5.4'
implementation 'org.apache.camel.springboot:camel-spring-boot-starter:3.11.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.4'
implementation files('D:\\sample\\app.jar')
}
请建议如何解决此问题。
1条答案
按热度按时间mcvgt66p1#
您似乎想要添加本地jar,请尝试以下操作:
将本地jar添加到您的模块gradle(而不是添加到应用gradle文件):