• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Spring 2.5 web mvc integration with Ibatis-2.3 using tomcat 6 server

Atharva Gupta
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

i am facing issue in loading sql-map-config.xml from applicationContextIBatis.xml

if I am placing sql-map-config.xml file in classes folder uder WEB-INF, then it is loading that sql-map-config.xml form applicationContextIBatis.xml.

but issue is that I am getting sqlMapClient object and dataSource as null under SqlMapClientTemplate object

find applicationContextIBatis.xml code below

<?xml version="1.0" encoding="UTF-8"?>
<bean id="hsqlDS" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbc.JDBCDriver" />
<property name="url" value="jdbc:hsqldb:file:/HSQL_DataBase/testdb" />
<property name="username" value="SA" />
<property name="password" value="" />


<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:ibatis/persistanceModel/sql-map-config.xml"/>
<property name="dataSource" ref="hsqlDS"/>

<bean id="usrDao" class="demo.dao.pkg.UserDao">
<property name="dataSource">
<ref local="hsqlDS" />
<property name="sqlMapClient" ref="sqlMapClient" />


find code for sql-map-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"

<settings useStatementNamespaces="true" />
<sqlMap resource="user.xml" />


fing web.xml file below :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">


<description>Loading Spring Configuration</description>



find the attached directory structure for the project in attachement :

Please help me for the issue.
Thanks in advance.
[Thumbnail for dirStructure.jpg]
Directory Structure for web project
Atharva Gupta
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have find out the solution for my problem.

actually I m not getting the bean object by applicationContext, directly I m creating the object of the service class in my Servlet.

and one more cofiguration I have not done in applicationContext.xml file, I have not created bean for my service and creating a parametarized constructor having dao as a parameter.

here are my changes.

applicationContext.xml file, i have added below code.

<bean id="loginService" class="demo.service.pkg.LoginServiceImpl">
<ref local="loginDao"/>

LoginServiceImpl.java, i have created a parametarized constructor having dao as a parameter.

public LoginServiceImpl(LoginDAO loginDAO){
this.loginDAO = loginDAO;

and LoginServlet.java, I have added below code,

public void init() throws ServletException {
applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());

and getting the service object by calling,


Now, my application is working fine.
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!