Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9195961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:44:42+00:00 2026-06-17T21:44:42+00:00

when I integrate spring and mybatis, I encountered a error output, saying that: Bean

  • 0

when I integrate spring and mybatis, I encountered a error output, saying that:

Bean named ‘sqlSessionFactory’ must be of type [org.mybatis.spring.SqlSessionFactoryBean], but was actually of type [org.apache.ibatis.session.defaults.DefaultSqlSessionFactory]

here is my code snippet:

ApplicationContext context = new ClassPathXmlApplicationContext("spring_mybatis_integration/spring_config.xml");
    SqlSessionFactoryBean sqlSessionFactoryBean = context.getBean("sqlSessionFactory", org.mybatis.spring.SqlSessionFactoryBean.class);

here is my bean definition in xml:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="configLocation" value="spring_mybatis_integration/mybatis_config.xml"></property>
  <property name="dataSource" ref="dataSource"></property>
</bean>

as you can see, both in java code and in xml file, I associate the bean sqlSessionFactory with class org.mybatis.spring.SqlSessionFactoryBean, why does the error output tell me another non-relative class name org.apache.ibatis.session.defaults.DefaultSqlSessionFactory?

Thanks a lot!

Version Info:

  • mybatis 3.1.1
  • spring 3.2.0
  • mybatis-spring 1.1.1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:44:43+00:00Added an answer on June 17, 2026 at 9:44 pm

    There is no point to accessSqlSessionFactoryBean via dependency injection, normally we work with the objects created by the Factory Beans, not the Factory Beans themselves, in this case the Factory Bean returns a DefaultSqlSessionFactory instance.

    See Customizing instantiation logic with the FactoryBean Interface

    But if you really want to access the FactoryBean instance, you should use ampersand symbol & see Spring: Getting FactoryBean object instead of FactoryBean.getObject()

    Yes, the concept of the Factory Beans that return factories may be a bit confusing, but that is how things work in Spring.

    So it’s likely SqlSessionFactory instead of the SqlSessionFactoryFactoryBean is what you want.

    update: actually MyBatis even explained this in the documentation on SqlSessionFactoryBean

    Note that SqlSessionFactoryBean implements Spring’s FactoryBean
    interface (see section 3.8 of the Spring documentation). This means
    that the bean Spring ultimately creates is not the
    SqlSessionFactoryBean itself, but what the factory returns as a result
    of the getObject() call on the factory. In this case, Spring will
    build an SqlSessionFactory for you at application startup and store it
    with the name sqlSessionFactory

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSP struts application that uses Spring to integrate with the services/dao/database.
I just wants to know that is it possible to integrate Displaytag with spring
I'm trying to integrate Struts 2 with Spring and Hibernate. There are things that
trying to integrate hibernate and spring ,I ran into this error SEVERE: Context initialization
We all know, that Spring MVC integrate well with Hibernate Validator and JSR-303 in
is it a must to use kodo jdo if want to integrate with spring?
I keep having this error when I'm trying to integrate Spring JMS into my
How can i integrate jqgrid, mybatis, spring mvc and postgresql when i have to
I am trying to integrate Spring Security in my extjs project,but encountered the following
I am trying to integrate Hibernate 3 with Spring 3.1.0. The problem is that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.