我使用ServiceMix 3.5 我有多个ServiceAssemblies,每个都用于ServiceUnit。 服务单元共有许多库,所以我在maven pom中用“提供”范围标记它们。 共享库包含我希望服务单元共享的所有库。 我根据以下maven pom.xml构建,但效果很简单:
抛出java.lang.ClassNotFoundException: 类加载器中的org.apache.commons.dbcp.BasicDataSource org.apache.xbean.spring.context.FileSystemXmlApplicationContext
我可以做些什么(可能使用jbi-maven-plugin),以便我的服务单位可以使用共享库中的jar?
共享库服务单元pom:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aaa.bbb</groupId>
<artifactId>SHARED_SU</artifactId>
<packaging>jbi-service-unit</packaging>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>aaa.bbb</groupId>
<artifactId>theParent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<build>
<defaultGoal>install</defaultGoal>
<plugins/>
</build>
<properties><componentName>servicemix-camel</componentName></properties>
<dependencies>
...
</dependencies>
</project>
共享库服务单元pom:
<?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>aaa.bbb</groupId>
<artifactId>SHARED_SA</artifactId>
<packaging>jbi-shared-library</packaging>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>aaa.bbb</groupId>
<artifactId>theParent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>aaa.bbb</groupId>
<artifactId>SHARED_SU</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>jbi-maven-plugin</artifactId>
<version>3.2.3</version>
<extensions>true</extensions>
<configuration>
<type>service-assembly</type>
<classLoaderDelegation>parent-first</classLoaderDelegation>
</configuration>
</plugin>
</plugins>
</build>
</project>
需要使用共享库的服务单元的Pom:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aaa.bbb</groupId>
<artifactId>theServiceUnit</artifactId>
<packaging>jbi-service-unit</packaging>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>aaa.bbb</groupId>
<artifactId>theParent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>jbi-maven-plugin</artifactId>
<version>3.2.3</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
<dependencies>
... <!-- all "PROVIDED" in scope-->
<properties>
<componentName>servicemix-camel</componentName>
</properties>
</project>
服务单位服务程序集的Pom
<?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>aaa.bbb</groupId>
<artifactId>theServiceAssembly</artifactId>
<packaging>jbi-service-assembly</packaging>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>aaa.bbb</groupId>
<artifactId>theParent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>aaa.bbb</groupId>
<artifactId>theServiceUnit</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>jbi-maven-plugin</artifactId>
<version>3.2.3</version>
<extensions>true</extensions>
<configuration>
<type>service-assembly</type>
</configuration>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:0)
我认为您误解了JBI Component / SharedLib / SA / SU或类加载器JBI的工作原理,请查看here以获取更多详细信息。
我无法理解“共享库服务单元pom”的含义,因为在每个JBI规范中,SharedLib不应该有任何服务单元,它只是由JBI组件引用,如servicemix-camel,all servicemix JBI组件仅引用一个默认的SharedLib,其名称为servicemix-shared。
类org.apache.commons.dbcp.BasicDataSource来自commons-dbcp.jar,但是commons-dbcp.jar不在smx3.x默认的sharedlib servicemix-shared中 - $ {version} -installer.zip,因此,默认情况下,除非您在SU的xbean.xml中明确添加<library>your_shared_lib_name</library>
,否则所有servicemix-camel su都无法看到此类。