在Jboss FUSE中配置数据库连接 [英] Configuring database connection in Jboss FUSE

查看:134
本文介绍了在Jboss FUSE中配置数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在JBOSS FUSE中配置数据库的一种方法是使用blueprint.xml. blueprint.xml中的以下配置有效

One way I know to configure DB in JBOSS FUSE is to use blueprint.xml. Below configuration in blueprint.xml works

<bean id="gemsDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="${gems_url}" />
    <property name="username" value="${gems_username}" />
    <property name="password" value="${gems_password}" />
    <property name="maxIdle" value="5" />
    <property name="minIdle" value="1" />
    <property name="initialSize" value="1" />
</bean>

但是,有什么方法可以在JBOSS容器特定的配置文件中对其进行配置.例如-在JBOSS EAP中,我们可以在standalone.xml中对其进行配置.在类似的行上,我们可以在JBOSS FUSE中对其进行配置吗?

However, Is there any way to configure it in JBOSS container specific configuration file. For example - In JBOSS EAP we can configure it in standalone.xml. On similar lines can we configure it in JBOSS FUSE?

推荐答案

您可以在包中定义数据源并将其导出.在其他捆绑软件中,您可以像服务一样导入和使用它.

You can define a Datasource in a bundle and export it. In other bundles you import and use it like a service.

安装这些功能

features:install jdbc
features:install jndi

数据源包

将XML文件拖放到 deploy 文件夹中,其中包含以下内容:

Datasource bundle

Drop an XML file inside deploy folder with following content:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

    <bean id="dataSource" class="org.postgresql.jdbc3.Jdbc3SimpleDataSource">
        <property name="url" value="jdbc:postgresql://localhost:5432/databasename"/>
        <property name="user" value="username"/>
        <property name="password" value="xxx"/>
    </bean>

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

这将导出具有javax.sql.DataSource接口和JNDI名称的服务

This will export a service with javax.sql.DataSource interface and a JNDI name

当分发包需要数据源时,请OSGi注入它.

When a bundle needs the datasource, ask OSGi to inject it.

<blueprint>
    <reference id="yourDatabaseDs"
           interface="javax.sql.DataSource"
           availability="mandatory"
           filter="(osgi.jndi.service.name=jdbc/yourdatabasename_ds)"/>
</blueprint>

使用您提供的JNDI名称检索正确的数据源.
使用availability="mandatory",您可以强制捆绑包等待数据源可用.没有此参考资料,捆绑软件将无法启动.

The right Datasource is retrieved using the JNDI name you provided.
Using availability="mandatory" you can force your bundle to wait for the Datasource to become available. The bundle won't start without this reference.

您需要使用的数据库正确的JDBC驱动程序.

You need the correct JDBC drivers for the database you are using.

您现在在JBoss Fuse控制台中有很多命令可以与数据库进行交互,例如jdbc:datasources,它将列出所有可用的数据源.借助jdbc:query,您可以对数据库运行任何SQL(有助于调试问题和测试连接)

You have a lot of commands in JBoss Fuse console to interact with the database now, like jdbc:datasources that will list all available datasources. With jdbc:query you can run any SQL against your DB (good for debugging issues and testing the connection)

这篇关于在Jboss FUSE中配置数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆