The Bean class in Spring configuration uses the meaning of the factory bean to parse

Source: Internet
Author: User

The Bean class in Spring configuration uses the meaning of the factory bean to parse

The beautiful Life of the Sun Vulcan (http://blog.csdn.net/opengl_es)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Sun Vulcan's Beautiful Life-this blog focuses on Agile development and mobile and IoT device research: IOS, Android, HTML5, Arduino, Pcduino , Otherwise, the article from this blog refused to reprint or re-reproduced, thank you for your cooperation.



    <bean id= "Studentmapper" class= "Org.mybatis.spring.MapperFactoryBean" >        <property name= " Mapperinterface "value=" Com.manager.data.StudentMapper "/>        <property name=" sqlsessionfactory "ref=" Sqlsessionfactory "/>    </bean>

1. This is a bean configured in Spring's configuration file;

Of course, Spring can have more than one configuration file, and the final Bean will be instantiated, assembled in XML configuration,

The so-called assembly is who is the attribute, it is assigned to its properties, first-level assembly completed.


2, in the case of the bean in XML instantiation definition, see:

<bean id= "Studentmapper" class= "Org.mybatis.spring.MapperFactoryBean" >
The ID is used to identify the bean, or the name of the class when instantiated in Java code;

Who does this class refer to? Of course it's the class that's behind it!

However, here is a Kit Kat, the following class is Factorybean, no way to be instantiated, so, is automatically called by the Spring framework of the factory Bean factory method to obtain an instance of the Studentmapper class,

In this case, the preceding ID is not referring to an instance of the following class class, and of course the reference type represented by the ID is not.

This time I know the reason of MyBatis's Mapper.


3, however, there is a more convenient way to achieve the integration of MyBatis and srping, that is, mybatis-srping components, we use the MyBatis package of the various package classes, after the introduction of it, the corresponding name of the same class in it:

<bean id= "Sqlsessionfactory" class= "Org.mybatis.spring.SqlSessionFactoryBean" >

And the Mapper instance object gets, and is no longer so troublesome, using the way in mybatis-spring:

<bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" >

With this sentence, all Mapper are searched by the location specified by their property expression value, all of them can be instantiated correctly;

It is freely referenced in all Spring configuration file context contexts.







The Bean class in Spring configuration uses the meaning of the factory bean to parse

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.