Spring JdbcDaoSupport Jboss Datasource
In our previous tutorial you saw how to use JdbcDaoSupport and JDBCTemplate to connect the database and perform CRUD operation. We had used properties file to keep database configuration and took its reference to connect database and perform operation.
In this demo you will see how to configure data source in Jboss application server and get data base connection by JNDI using JbbcDaoSupport.
Note: We will use MySQL database for configuration and test.
- Please follow this tutorial to configure data source on Jboss application server
- Please do project setup and configuration from Spring JdbcDaoSupport Example
Below are summary of changes from properties file to use Jboss datasource and you have to make changes only one file:
- dispatcher-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:component-scan base-package="com.javahonk.controller" /> <mvc:annotation-driven /> <context:property-placeholder location="classpath:database/database.properties" /> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:/mysqldb" /> </bean> <bean id="springJdbDaoSupportDAO" class="com.javahonk.dao.SpringJdbcDaoSupportDAOImpl"> <property name="dataSource" ref="dataSource"></property> </bean> <bean id="springJdbDaoSupportService" class="com.javahonk.services.SpringJdbcDaoSupportServiceImpl" /> </beans>
- For more details to configure data source on Jboss application server please visit here