Jboss 7 EPA datasource configuration using oracle and spring boot

In this post, we are going to see Jboss 7 EPA Datasource configuration using oracle and spring boot. Here we are going to create a Spring boot application. As we know Spring boot provides embedded tomcat for deployment purpose but here we are going to use JBoss 7 for deployment. The JBoss configuration steps will be the same even for other databases.

We can define datasource in standalone.xml as following.

<datasources>
<datasource jndi-name=”java:jboss/datasources/BootWarDeployment” pool-name=”BootWarDeployment” enabled=”true” use-java-context=”true”>
<connection-url>jdbc:oracle:thin:@localhost:1521:XE</connection-url>
<driver>oracle</driver>
<security>
<user-name>SYSTEM</user-name>
<password>oracle1</password>
</security>
</datasource>
<drivers>
<driver name=”oracle” module=”com.oracle.jdbc”>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>

 

Let’s see an example where we will see how to modify standalone.xml and how to create module.xml which are needed for JNDI Datasource configuration.

Jboss 7 EPA Datasource configuration using oracle and spring boot example.

Prerequisites –

  • JDK 1.8
  • Oracle 10g
  • Eclipse
  • maven
  • JBoss 7 EPA

 

Open eclipse and create maven project, Don’t forget to check ‘Create a simple project (skip)’click on next. Fill all details(GroupId – BootWarDeployment, ArtifactId – BootWarDeployment and name – BootWarDeployment) and click on finish. Keep packaging as the jar.

Open pom.xml  and modify the pom.xml with below code.

 

Note – In pom.xml we have defined javac.exe path in configuration tag. You need to change accordingly i.e where you have installed JDK.

Let maven download all necessary jar. Once it is done we will able to see the maven dependency folder which contains different jar files. Create classes and interfaces as below.

Jboss 7 EPA datasource configuration using oracle and spring boot

 

Book.java

 

BookService.java

 

BookRepository.java

 

BookServiceImpl.java

 

BookController.java

 

SpringMain.java

 

AppConfiguration.java

 

We are done with the coding part. Now give the build use mvn clean install. In target folder we should have war file with name BootWarDeployment.war.

Jboss 7 EPA datasource configuration using oracle and spring boot

 

 

We have BootWarDeployment.war now. Let’s deploy the war file using JBoss.

Download JBoss and modify the standalone.xml. Here we are going to configure datasource. we will provide database details.

standalone.xml.

 

<subsystem xmlns=”urn:jboss:domain:bean-validation:1.0″/>
<subsystem xmlns=”urn:jboss:domain:core-management:1.0″/>
<subsystem xmlns=”urn:jboss:domain:datasources:5.0″>
<datasources>
<datasource jndi-name=”java:jboss/datasources/BootWarDeployment” pool-name=”BootWarDeployment” enabled=”true” use-java-context=”true”>
<connection-url>jdbc:oracle:thin:@localhost:1521:XE</connection-url>
<driver>oracle</driver>
<security>
<user-name>SYSTEM</user-name>
<password>oracle1</password>
</security>
</datasource>
<drivers>
<driver name=”oracle” module=”com.oracle.jdbc”>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>

These changes we need to do in standalone.xml. If you want to change port you need change as below.

 

<socket-binding-group name=”standard-sockets” default-interface=”public” port-offset=”${jboss.socket.binding.port-offset:0}”>
<socket-binding name=”management-http” interface=”management” port=”${jboss.management.http.port:1980}”/>
<socket-binding name=”management-https” interface=”management” port=”${jboss.management.https.port:7793}”/>
<socket-binding name=”ajp” port=”${jboss.ajp.port:2009}”/>
<socket-binding name=”http” port=”${jboss.http.port:7780}”/>
<socket-binding name=”https” port=”${jboss.https.port:5443}”/>
<socket-binding name=”txn-recovery-environment” port=”4712″/>
<socket-binding name=”txn-status-manager” port=”4713″/>
<outbound-socket-binding name=”mail-smtp”>
<remote-destination host=”localhost” port=”25″/>
</outbound-socket-binding>
</socket-binding-group>

 

We are almost done. Now we need to define module.xml. This is a very important step. we need to create some directory structure.

\jboss-eap-7.1.0\jboss-eap-7.1\modules\com\oracle\jdbc\main

Go inside modules folder and create folders com\oracle\jdbc\main and put ojdbc6.jar and also module.xml.

module.xml

 

Put the BootWarDeployment.war inside deployment folder(\jboss-eap-7.1\standalone\deployments).

 

Go inside bin folder and run standalone.bat file and deploy the war file.

 

Jboss 7 EPA datasource configuration using oracle and spring boot

 

Insert some record in book table as we have implemented only get operation and use the postman to test the rest URI.

 

Jboss 7 EPA datasource configuration using oracle and spring boot

 

That’s all about Jboss 7 EPA Datasource configuration using oracle and spring boot. If you feel any problem to run this application please leave a message in the comment box.

Check Datasource configuration docs here.

You may like –

 

JBoss Deployment docs.

 

 

Top