在jbossfuse中配置数据库连接
我知道在JBOSS FUSE中配置DB的一种方法是使用blueprint.xml。 blueprint.xml中的以下配置有效在jbossfuse中配置数据库连接,jboss,jbossfuse,jboss-eap-7,Jboss,Jbossfuse,Jboss Eap 7,我知道在JBOSS FUSE中配置DB的一种方法是使用blueprint.xml。 blueprint.xml中的以下配置有效 <bean id="gemsDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /&
<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中配置它吗?JBOSS FUSE提供了与各种数据源的集成。您需要像以前一样对它们进行捆绑配置。但是在容器级别上没有这样的配置。您可以在捆绑包中定义一个数据源并将其导出。在其他捆绑包中,您可以像导入服务一样导入和使用它 先决条件 安装这些功能
features:install jdbc
features:install jndi
数据源包
将包含以下内容的XML文件放入deploy文件夹中:
<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>
使用您提供的JNDI名称检索正确的数据源。使用
availability=“mandatory”
可以强制捆绑包等待数据源可用。没有此引用,捆绑包将无法启动
对于正在使用的数据库,您需要正确的JDBC驱动程序
其他好东西
现在,JBoss Fuse控制台中有很多命令可以与数据库交互,比如将列出所有可用数据源的jdbc:datasources
。使用jdbc:query
可以对数据库运行任何SQL(有利于调试问题和测试连接)
<blueprint>
<reference id="yourDatabaseDs"
interface="javax.sql.DataSource"
availability="mandatory"
filter="(osgi.jndi.service.name=jdbc/yourdatabasename_ds)"/>
</blueprint>