Spring + iBatis // Part 3 // applicationContext
In the same location (as part 2), create another file called “applicationContext.xml”. Paste in the following content. Some explanation will follow below.
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:database.properties"/> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${database.class}"/> <property name="url" value="${database.url}"/> <property name="username" value="${database.username}"/> <property name="password" value="${database.password}"/> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <tx:annotation-driven/> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation" value="sqlmap-config.xml"/> <property name="dataSource" ref="dataSource"/> <property name="useTransactionAwareDataSource" value="true"/> </bean> <bean id="myDAO" class="com.example.dao.MyDAOImpl"> <property name="sqlMapClient" ref="sqlMapClient"/> </bean> </beans>
Notes:
- classpath:database.properties points to the database.properties files we created earlier. If you used a different location, you may need to update this value.
- sqlmap-config.xml is a file we will create later. It will hold our sql and mapping information.
- myDAO is our data access interface. This will be created later also. You may need to change the name of this, and it’s class reference.
Advertisement
Categories: iBATIS, Java Language, Spring
applicationContext, configuration, iBATIS, java, jDeveloper, setup, Spring, tutorial
