Configuring multiple databases and data sources in JBoss

Source: Internet
Author: User
Tags min jboss jboss server

JBoss is a very powerful Java EE application Server, but this powerful feature also brings complexity. The author of this article, Marcus Zarra, analyzes how to configure multiple databases and data sources in JBoss.

Configure a data source

The default setup process for JBoss is a total of three configuration options: all, default, and minimum (minimal). If you start the JBoss server for the first time without any parameters attached, it will naturally run the default configuration. If you need to run another configuration, you must run the startup script using the-c parameter, as follows:

${jboss. Root}/bin/run.sh-c Minimal

Starting JBoss In this manner indicates that it replaces the default configuration with a minimal server configuration. But this technique is useful when trying to change the configuration of JBoss itself. You can modify the operation in different configurations and roll back to the default configuration if necessary. But before you mess with the data source, you should copy the default configuration so that you can safely manipulate the copy (in this article, I called my copy example, so there are four configuration information in the server directory: all, default, minimum, and example).

The first step in changing the default data source in JBoss is to configure a new data source. All of the database configurations in JBoss are defined in the Deploy directory of the server directory where you work (in the case of Server/example/deploy). The default database that JBoss uses is a pure Java database hypersonic. The configuration information for this database is located in the Hsqldb-ds.xml file. This XML configuration file describes how to connect to the hypersonic database. After deleting all the comments in this file, we get the configuration information shown below:

<?xml version= "1.0" encoding= "UTF-8"
<datasources>
<local-tx-datasource>
<jndi-name>defaultds</jndi-name>
<connection-url>
Jdbc:hsqldb:${jboss.server.data.dir} ${/}hypersonic${/}localdb
</connection-url>
<driver-class>org.hsqldb.jdbcdriver</ Driver-class>
<user-name>sa</user-name>
<password></password>
<min-p Ool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
< Idle-timeout-minutes>0</idle-timeout-minutes>
<track-statements/>
<security-domain> Hsqldbrealm</security-domain>
<depends>jboss:service=hypersonic,database=localdb</depends
</local-tx-datasource>
<mbean code= "Org.jboss.jdbc.HypersonicDatabase name=" jboss:service= Hypersonic,database=localdb "
<attribute name=" Database">localdb</attribute>
<attribute name=" Inprocessmode ">TRUE</ATTRIBUTE>
</mbean
</datasources>

Most of these parameters are similar to the JDBC parameters. The first part of the root is <local-tx-datasource>. This is where you define the database and how to connect to the database: Driver, URL, username, and password. You also define how many connections should be in the connection pool.

The second step contains two interesting parameters:

· <security-domain> allows you to configure the database username and password in the Login-config.xml file rather than in the data source configuration information.

· <depends> Specifies that the service starts only after the service on which it relies is started. This parameter allows you to write a service that the database should run correctly. The <depends> label also instructs JBoss to close some data items as needed. This tag in the example indicates that the Mbean must be started before the database is started and shut down after the database has been shut down.

After the data source is defined, the rest of the server is ready to use it. Any other service or configuration that you want to use this data source must refer to it using the Jndi name. In the example, the Jndi name is Defaultds.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.