GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes Problem with Spring 2.5 web mvc integration with Ibatis-2.3 using tomcat 6 server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem with Spring 2.5 web mvc integration with Ibatis-2.3 using tomcat 6 server" Watch "Problem with Spring 2.5 web mvc integration with Ibatis-2.3 using tomcat 6 server" New topic
Author

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

Atharva Gupta
Greenhorn

Joined: Jun 06, 2012
Posts: 16
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"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<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>

<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>

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

</beans>

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"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>

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

</sqlMapConfig>

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">
<display-name>JspServletApp</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>WEB-INF/log4j.properties</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<description>Loading Spring Configuration</description>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContextIBatis.xml</param-value>
</context-param>

<servlet>
<description></description>
<display-name>UserServlet</display-name>
<servlet-name>UserServlet</servlet-name>
<servlet-class>demo.servlet.pkg.UserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserServlet</servlet-name>
<url-pattern>/UserServlet</url-pattern>
</servlet-mapping>

</web-app>

find the attached directory structure for the project in attachement :


Please help me for the issue.
Thanks in advance.



[Thumbnail for dirStructure.jpg]

Atharva Gupta
Greenhorn

Joined: Jun 06, 2012
Posts: 16
Hi,

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">
<constructor-arg>
<ref local="loginDao"/>
</constructor-arg>
</bean>

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,

@Override
public void init() throws ServletException {
super.init();
applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
}

and getting the service object by calling,

loginService=(LoginService)applicationContext.getBean("loginService");

Now, my application is working fine.
 
GeeCON Prague 2014
 
subject: Problem with Spring 2.5 web mvc integration with Ibatis-2.3 using tomcat 6 server