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