数据源问题:java.lang.ClassNotFoundException:org.springframework.jdbc.datasource.DriverManagerDataSource

Datasource issue : java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource

你好 Fuse 开发者

我是 fuse world m 的初学者,现在尝试开发 JDBC 项目,遇到问题希望您能帮我解决

1- 我将 Oracle JDBC 驱动程序添加到 EAP Fuse 服务器

Oracle JDBC Driver

2- 我创建了数据源并对其进行了测试

datasource

3-骆驼语境

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="        http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd        http://camel.apache.org/schema/spring https://camel.apache.org/schema/spring/camel-spring.xsd">
    <bean
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        destroy-method="close" id="dataSource">
        <property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
        <property name="url" value="jdbc:oracle://192.168.56.205:1521/orcl"/>
        <property name="username" value="hr"/>
        <property name="password" value="hr"/>
    </bean>
    <camelContext id="spring-context" xmlns="http://camel.apache.org/schema/spring">
        <route id="_route1">
            <from id="_to1" uri="direct:HelloHR"/>
            <log id="_log1" message="======== Start Flow ======="/>
            <setProperty id="_setProperty1" propertyName="DbQuery">
                <simple>sql: select * from employees;</simple>
            </setProperty>
            <setBody id="_setBody1">
                <simple>{property.DbQuery}</simple>
            </setBody>
            <to id="_to2" uri="jdbc:dataSource"/>
            <log id="_log2" message="${body}"/>
        </route>
    </camelContext>
    <!-- Just add a demo to show how to bind a date source for camel in Spring-->
</beans>

4- pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany</groupId>
  <artifactId>camel-test-spring</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>Fuse on EAP Camel Spring Application</name>
  <description>Fuse on EAP Camel Example using Spring</description>
  <properties>
    <version.jboss.arquillian>1.1.10.Final</version.jboss.arquillian>
    <maven.compiler.source>1.8</maven.compiler.source>
    <version.wildfly.arquillian>2.1.0.Final</version.wildfly.arquillian>
    <server.config>standalone-camel.xml</server.config>
    <version.maven.war.plugin>3.0.0</version.maven.war.plugin>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <version.wildfly.maven.plugin>1.2.0.Final</version.wildfly.maven.plugin>
    <maven.compiler.target>1.8</maven.compiler.target>
    <version.wildfly>7.1.0.GA-redhat-11</version.wildfly>
    <version.maven.surefire.plugin>2.20.1</version.maven.surefire.plugin>
    <jboss.home>${env.JBOSS_HOME}</jboss.home>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <version.maven.compiler.plugin>3.8.0</version.maven.compiler.plugin>
    <fuse.version>7.8.0.fuse-sb2-780038-redhat-00001</fuse.version>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.2.0</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>2.8.0</version>
      </dependency>
      <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-dbcp2</artifactId>
        <version>2.8.0</version>
      </dependency>
      <dependency>
        <groupId>org.geotools.jdbc</groupId>
        <artifactId>gt-jdbc-oracle</artifactId>
        <version>25.1.jre8</version>
      </dependency>
      <dependency>
        <groupId>oracle</groupId>
        <artifactId>oracle-jdbc</artifactId>
        <version>6</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>5.3.8</version>
</dependency>
      <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jdbc</artifactId>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-dao</artifactId>
        <version>2.0.8</version>
      </dependency>
      <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jdbc</artifactId>
        <version>x.x.x</version>
      </dependency>
      <dependency>
        <groupId>org.jboss.redhat-fuse</groupId>
        <artifactId>fuse-eap-bom</artifactId>
        <version>${fuse.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.spec.javax.servlet</groupId>
      <artifactId>jboss-servlet-api_3.1_spec</artifactId>
      <version>1.0.0.Final-redhat-1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.arquillian.junit</groupId>
      <artifactId>arquillian-junit-container</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-josql</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-jdbc</artifactId>
      <version>2.23.2.fuse-780036-redhat-00001</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <id>jboss-public-repository</id>
      <url>http://repository.jboss.org/nexus/content/groups/public/</url>
    </repository>
    <repository>
      <id>red-hat-ga-repository</id>
      <url>https://maven.repository.redhat.com/ga</url>
    </repository>
  </repositories>
  <build>
    <testResources>
      <testResource>
        <filtering>true</filtering>
        <directory>src/test/resources</directory>
      </testResource>
    </testResources>
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${version.maven.compiler.plugin}</version>
        <configuration>
          <source>${maven.compiler.source}</source>
          <target>${maven.compiler.target}</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>${version.maven.war.plugin}</version>
      </plugin>
      <plugin>
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-maven-plugin</artifactId>
        <version>${version.wildfly.maven.plugin}</version>
        <configuration>
          <version>${version.wildfly}</version>
          <serverConfig>${server.config}</serverConfig>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${version.maven.surefire.plugin}</version>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>arq-managed</id>
      <dependencies>
        <dependency>
          <groupId>org.wildfly.arquillian</groupId>
          <artifactId>wildfly-arquillian-container-managed</artifactId>
          <version>${version.wildfly.arquillian}</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>
    <profile>
      <id>arq-remote</id>
      <dependencies>
        <dependency>
          <groupId>org.wildfly.arquillian</groupId>
          <artifactId>wildfly-arquillian-container-remote</artifactId>
          <version>${version.wildfly.arquillian}</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>
    <profile>
      <id>jdk9+-build</id>
      <activation>
        <jdk>[9,)</jdk>
      </activation>
      <dependencies>
        <dependency>
          <groupId>javax.annotation</groupId>
          <artifactId>javax.annotation-api</artifactId>
          <version>1.3.1</version>
        </dependency>
        <dependency>
          <groupId>javax.xml.ws</groupId>
          <artifactId>jaxws-api</artifactId>
          <version>2.3.0</version>
          <exclusions>
            <exclusion>
              <artifactId>jaxb-api</artifactId>
              <groupId>javax.xml.bind</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>jakarta.xml.bind</groupId>
          <artifactId>jakarta.xml.bind-api</artifactId>
          <version>2.3.2.redhat-00001</version>
        </dependency>
        <dependency>
          <groupId>com.sun.activation</groupId>
          <artifactId>javax.activation</artifactId>
          <version>1.2.0</version>
        </dependency>
        <dependency>
          <groupId>org.apache.geronimo.specs</groupId>
          <artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
          <version>1.1.3</version>
        </dependency>
        <dependency>
          <groupId>com.sun.xml.messaging.saaj</groupId>
          <artifactId>saaj-impl</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.geronimo.specs</groupId>
          <artifactId>geronimo-jta_1.1_spec</artifactId>
        </dependency>
        <dependency>
          <groupId>org.jboss.spec.javax.rmi</groupId>
          <artifactId>jboss-rmi-api_1.0_spec</artifactId>
          <version>1.0.5.Final-redhat-1</version>
        </dependency>
      </dependencies>
    </profile>
    <profile>
      <id>jdk12+-build</id>
      <activation>
        <jdk>[12,)</jdk>
      </activation>
      <properties>
        <version.maven.war.plugin>3.2.2</version.maven.war.plugin>
      </properties>
    </profile>
  </profiles>
</project>

5-Maven 依赖项

Maven dependencies

6- 引用的库

Referenced libraries

我的项目配置有什么问题?我该如何解决? 最好的问候,

commons-dbcpDriverManagerDataSource 并不是真正需要的,因为您已经将 DataSource 配置为由 EAP 容器管理。因此,您可以用这样的 JNDI 查找替换 dataSource bean。

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:jboss/OracleXADS" />
</bean>