1

我试图构建骆驼 sql 应用程序,但我有堆栈。

我在页面中找到了有关 camel-sql 的信息http://camel.apache.org/sql-component.html

我已经创建了 xml 配置,如示例所示,在我的 FUSE ESB 中我发现了异常:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name
     'camel-21': Invocation of init method failed; nested exception is 
    org.springframework.beans.factory.CannotLoadBeanClassException: 
Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] 
for bean with name 'esb' defined in URL [bundle://249.2:0/META-INF/spring/camel-context.xml]; nested exception is java.lang.ClassNotFoundException: 
org.springframework.jdbc.datasource.DriverManagerDataSource not found from bundle [camel]

但在我的保险丝控制台中,我有弹簧 jdbc:

karaf@root> osgi:list | grep Spring

ID 状态蓝图 Spring 级别名称 [73] [Active] [] [] [60] Spring Beans (3.0.5.RELEASE)

[ 74] [活动] [ ] [ ] [ 60] Spring 上下文支持 (3.0.5.RELEASE)

[ 75] [活动] [ ] [ ] [ 60] Spring 上下文 (3.0.5.RELEASE)

[ 76] [Active ] [ ] [ ] [ 60] Spring 表达式语言 (3.0.5.RELEASE)

[ 77] [活动] [ ] [ ] [ 60] Spring ASM (3.0.5.RELEASE)

[ 78] [活动] [ ] [ ] [ 60] Spring Core (3.0.5.RELEASE)

[ 79] [活动] [ ] [ ] [ 60] Spring AOP (3.0.5.RELEASE)

[ 87] [活动] [ ] [ ] [ 60] Apache XBean :: Spring (3.8)

[ 92] [活动] [ ] [ ] [ 50] Spring事务(3.0.5.RELEASE)

[ 94] [活动] [ ] [ ] [ 50] Spring JMS (3.0.5.RELEASE)

[169][活动][][][50]Apache XBean::Spring (3.7)

[223][活动][][][60]Spring Web (3.0.5.RELEASE)

[224][活动][][][60]Spring Web Servlet (3.0.5.RELEASE)

[252][活动][][][50]Spring JDBC(3.0.5.RELEASE)

我需要做什么 ?

更新:

我的 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>camelWs</groupId>
  <artifactId>camel</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>

  <name>A Camel Route</name>
  <url>http://www.myorganization.org</url>

  <dependencies>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
      <version>2.9.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-spring</artifactId>
      <version>2.9.0</version>
    </dependency>

    <!-- logging -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.6.1</version>
    </dependency> 
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.6.1</version>
    </dependency>
    <dependency>
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.16</version> 
    </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>3.0.5.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.0.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>3.0.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>3.0.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-sql</artifactId>
            <version>2.8.0</version>
            <!-- use the same version as your Camel core version -->
        </dependency>
  </dependencies>

  <build>
    <defaultGoal>install</defaultGoal>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>


        </configuration>
      </plugin>
      <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.1.0</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Import-Package>
                            org.springframework.jdbc.datasource
                        </Import-Package>

                    </instructions>
                </configuration>
            </plugin>

      <!-- allows the route to be ran via 'mvn camel:run' -->
      <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-maven-plugin</artifactId>
        <version>2.9.0</version>
        <configuration>

          <instructions>

                        <Import-Package>
                            *,
                            org.springframework.jdbc,
                            org.springframework.jdbc.datasource

                        </Import-Package>

                           <DynamicImport-Package>camel.*</DynamicImport-Package>

                    </instructions>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

但是当我使用 osgi:headers 时,我看不到导入的类,我的 pom.xml 有什么问题?

osgi:标题:

camel (271)
-----------
Manifest-Version = 1.0
Bnd-LastModified = 1332154265299
Archiver-Version = Plexus Archiver
Tool = Bnd-0.0.357
Originally-Created-By = Apache Maven
Generated-By-Ops4j-Pax-From = wrap:file:/.../$Bundle-SymbolicName=camel&Bundle-Version=1.0.0.SNAPSHOT
Build-Jdk = 1.6.0_29
Created-By = 1.6.0_29 (Apple Inc.)

Bundle-Name = camel
Bundle-SymbolicName = camel
Bundle-Version = 1.0.0.SNAPSHOT
Bundle-ManifestVersion = 2

Private-Package = 
    .
Import-Package = 
    camel;resolution:=optional,
    org.apache.camel.builder;resolution:=optional,
    org.apache.camel.model;resolution:=optional,
    org.apache.camel.spring;resolution:=optional
Export-Package = 
    camel;uses:="org.apache.camel.builder,org.apache.camel.model,org.apache.camel.spring"
4

3 回答 3

3

OSGi 对于轻松安装和使用 JDBC 驱动程序可能有点麻烦。一个经过验证的解决方案是将 JDBC 驱动程序作为片段包安装到您的包中。

它已在 FuseSource 论坛上进行了讨论,其中有如何解决此问题的说明。起点是此链接: http://fusesource.com/forums/thread.jspa?messageID=13043& #13043,然后按照其他讨论的参考资料了解更多详细信息以及如何解决它。

于 2012-03-20T04:44:49.277 回答
0

你应该确保你的路由在org.springframework.jdbc.datasource上有一个导入包。您可以使用karaf中的header命令对其进行验证。

于 2012-03-19T10:07:26.530 回答
0

好的,我找到了解决方案。

这很容易——我只需要安装 mysql 连接器。

谢谢大家。

于 2012-06-25T07:10:44.873 回答