Announcement Announcement Module
Collapse
No announcement yet.
Spring iBATIS configuration problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring iBATIS configuration problem

    Hi,

    I am setting up project framework based on Spring an iBATIS2. I am new to these technologies and I am stuck with apparently quite simple problem. Below is the part of dataAccessContext.xml that is based on Spring Jpetstore example:

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
    <property name="configLocation"><value>WEB-INF/sql-map-config.xml</value></property>
    </bean>

    <bean id="userDao" class="test.dao.ibatis.SqlMapUserDao">
    <property name="dataSource"><ref local="dataSource"/></property>
    <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
    </bean>


    But when I try to test the setup I get the foloowing error:

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: sqlMapClient is required

    As I understand it is ok to refer to bean factory instead of bean itself. I could not find any info on Internet on the topic so any help is appreciated.

    Thanks in advance,
    Mak

  • #2
    Could you post the full stacktrace?

    Comment


    • #3
      Here is it:

      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: sqlMapClient is required
      java.lang.IllegalArgumentException: sqlMapClient is required
      at org.springframework.orm.ibatis.SqlMapClientTemplat e.afterPropertiesSet(SqlMapClientTemplate.java:123 )
      at org.springframework.orm.ibatis.support.SqlMapClien tDaoSupport.afterPropertiesSet(SqlMapClientDaoSupp ort.java:101)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:990)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:275)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:193)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:240)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveReference(Abstra ctAutowireCapableBeanFactory.java:898)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveValueIfNecessary (AbstractAutowireCapableBeanFactory.java:832)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:773)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:601)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:258)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:193)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:240)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:163)
      at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:236)
      at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:304)
      at org.springframework.web.context.support.XmlWebAppl icationContext.refresh(XmlWebApplicationContext.ja va:131)
      at org.springframework.web.struts.ContextLoaderPlugIn .createWebApplicationContext(ContextLoaderPlugIn.j ava:312)
      at org.springframework.web.struts.ContextLoaderPlugIn .initWebApplicationContext(ContextLoaderPlugIn.jav a:253)
      at org.springframework.web.struts.ContextLoaderPlugIn .init(ContextLoaderPlugIn.java:223)
      at org.apache.struts.action.ActionServlet.initModuleP lugIns(ActionServlet.java:839)
      at org.apache.struts.action.ActionServlet.init(Action Servlet.java:332)
      at javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
      at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1029)
      at org.apache.catalina.core.StandardWrapper.load(Stan dardWrapper.java:862)
      at org.apache.catalina.core.StandardContext.loadOnSta rtup(StandardContext.java:4013)
      at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4357)
      at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1083)
      at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:789)
      at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1083)
      at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:478)
      at org.apache.catalina.core.StandardService.start(Sta ndardService.java:480)
      at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2313)
      at org.apache.catalina.startup.Catalina.start(Catalin a.java:556)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:287)
      at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:425)

      Comment


      • #4
        Check your Dao. You're probably using both IBATIS 2 and 1 (jpetstore is using IBATIS 1.x, if I remember). Take a look here : http://www.springframework.org/docs/...m.html#d0e6209


        Arnaud

        Comment


        • #5
          Yes Spring Jpetstore uses iBATIS 1 but I have changed DAO according iBATIS 2 requirements. Below is the code:

          public class SqlMapUserDao extends SqlMapClientDaoSupport implements UserDao {

          public User getUser(String username, String password) throws DataAccessException {
          User user = new User();
          user.setUsername(username);
          user.setPassword(password);
          return (User) getSqlMapClientTemplate().queryForObject("getUser" , user);
          }

          The problem as I understand is that for some reason Spring IOC container refuses to accept beanFactory instead of bean though it should.
          I am confused... and stuck

          Comment

          Working...
          X