Fuse 6.3 dbcp basic datasource

2020-08-09 04:29发布

I am not able to get dbcp2 working in JBoss fuse 6.3. The code given below works fine in Fuse container.

<bean id="oracleDSTest" class="oracle.jdbc.pool.OracleDataSource"
        destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:XE" />
        <property name="username" value="hr" />
        <property name="password" value="hr" />
        <property name="maxIdle" value="5" />
        <property name="minIdle" value="1" />
        <property name="initialSize" value="1" />
    </bean>

    <service interface="javax.sql.DataSource" ref="oracleDSTest">
        <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/oracleDSTest" />
            <entry key="datasource.name" value="oracleDSTest" />
        </service-properties>
    </service>

But if I use org.apache.commons.dbcp.BasicDataSource instead of oracle.jdbc.pool.OracleDataSource it fails with the following error:

Error executing command: oracle.jdbc.driver.T4CConnection.isValid(I)Z

What could be the reason for this error?

1条回答
趁早两清
2楼-- · 2020-08-09 04:54

I am using ojdbc6-11.2.0.3.jar and the driver works in both configurations.

I tested it with a query from JBoss Fuse Console

jdbc:query jdbc/oracle 'select * from somewhere.sometable WHERE rownum < 5'

Check that JDBC and JNDI are installed

features:install jdbc
features:install jndi

You can drop an XML file with the following content into deploy/ to automagically have a datasource deployed.

OracleDataSource

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

    <bean id="oracleDSTest" class="oracle.jdbc.pool.OracleDataSource"
          destroy-method="close">
        <property name="URL" value="jdbc:oracle:thin:@db.host:1521:SID" />
        <property name="user" value="UrName" />
        <property name="password" value="YourPasswrd" />
    </bean>

    <service interface="javax.sql.DataSource" ref="oracleDSTest">
        <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/oracle" />
            <entry key="datasource.name" value="oracleDSTest" />
        </service-properties>
    </service>
</blueprint>

BasicDataSource

<bean id="oracleDSTest" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@db.host:1521:SID"/>
    <property name="username" value="UrName"/>
    <property name="password" value="YourPasswrd"/>
    <property name="maxIdle" value="5" />
    <property name="minIdle" value="1" />
    <property name="initialSize" value="1" />
</bean>

<service interface="javax.sql.DataSource" ref="oracleDSTest">
    <service-properties>
        <entry key="osgi.jndi.service.name" value="jdbc/oracle" />
        <entry key="datasource.name" value="oracleDSTest" />
    </service-properties>
</service>

Classloading

Please mind that this version of Oracle JDBC driver is not OSGi ready. To get everything to work under OSGi you may want to export Oracle classes from the System bundle.
Copy ojdbc6-11.2.0.3.jar (or your version) to lib/ folder of JBoss Fuse.
Edit etc/config.properties and add the packages to org.osgi.framework.system.packages property

org.osgi.framework.system.packages= \
  other.packages.here, \
  oracle.jdbc;version="11.2.0.3", \
  oracle.jdbc.driver;version="11.2.0.3", \
  oracle.jdbc.pool;version="11.2.0.3", \
  some.other.stuff

Reboot and check with exports | grep oracle

JBossFuse:karaf@root> exports | grep oracle
     0 oracle.jdbc; version=11.2.0.3
     0 oracle.jdbc.driver; version=11.2.0.3
     0 oracle.jdbc.pool; version=11.2.0.3
查看更多
登录 后发表回答