<commit_before><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
<!--
    Copyright 2010 The myBatis Team

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<!--
    version: $Id$
-->
<chapter id="mappers">
  <title>MapperFactoryBean</title>

  <para>
    Rather than code data access objects (DAOs) manually, Mybatis-Spring
    provides a dynamic proxy implmentation:
    <literal>MapperFactoryBean</literal>. This class lets you inject data
    mapper interfaces directly into your service beans. When using mappers you
    simply call them as you have always  called your DAOs, but you won't need
    to code any DAO implementation because MyBatis-Spring will create a proxy
    for you.
  </para>

  <para>
    With injected mappers your code will have no direct dependencies on MyBatis,
    Spring or MyBatis-Spring. The proxy that
    <literal>MapperFactoryBean</literal> creates handles opening and closing the
    session as well as translating any exceptions into Spring
    <literal>DataAccessExceptions</literal>. In addition, the proxy will
    start a new Spring transaction if required or participate in an existing
    one if necessary. 
  </para>

  <section id="mappers.setup">
    <title>Setup</title>
    <para>
      A data mapper interface is added to Spring like the following:

      <programlisting language="xml"><![CDATA[<bean id="userMapper" class="org.mybatis.spring.MapperFactoryBean">
  <property name="mapperInterface" value="org.mybatis.spring.sample.mapper.UserMapper" />
</bean>]]></programlisting>
    </para>

    <para>
      <literal>MapperFactoryBean</literal> creates a proxy class that
      implements <literal>UserMapper</literal> and injects it into the
      application. Because a proxy is created at runtime, the specified Mapper
      <emphasis>must</emphasis> be an interface, not an implementation class.
    </para>

    <para>
      If the UserMapper has a corresponding MyBatis XML mapper file, it will be
      parsed automatically by the <literal>MapperFactoryBean</literal>.
      In this case the mapper XML file <emphasis>must</emphasis> be in the same classpath <commit_msg>mapper files and interfaces must be in the same classpath<commit_after><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
<!--
    Copyright 2010 The myBatis Team

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<!--
    version: $Id$
-->
<chapter id="mappers">
  <title>MapperFactoryBean</title>

  <para>
    Rather than code data access objects (DAOs) manually, Mybatis-Spring
    provides a dynamic proxy implmentation:
    <literal>MapperFactoryBean</literal>. This class lets you inject data
    mapper interfaces directly into your service beans. When using mappers you
    simply call them as you have always  called your DAOs, but you won't need
    to code any DAO implementation because MyBatis-Spring will create a proxy
    for you.
  </para>

  <para>
    With injected mappers your code will have no direct dependencies on MyBatis,
    Spring or MyBatis-Spring. The proxy that
    <literal>MapperFactoryBean</literal> creates handles opening and closing the
    session as well as translating any exceptions into Spring
    <literal>DataAccessExceptions</literal>. In addition, the proxy will
    start a new Spring transaction if required or participate in an existing
    one if necessary. 
  </para>

  <section id="mappers.setup">
    <title>Setup</title>
    <para>
      A data mapper interface is added to Spring like the following:

      <programlisting language="xml"><![CDATA[<bean id="userMapper" class="org.mybatis.spring.MapperFactoryBean">
  <property name="mapperInterface" value="org.mybatis.spring.sample.mapper.UserMapper" />
</bean>]]></programlisting>
    </para>

    <para>
      <literal>MapperFactoryBean</literal> creates a proxy class that
      implements <literal>UserMapper</literal> and injects it into the
      application. Because a proxy is created at runtime, the specified Mapper
      <emphasis>must</emphasis> be an interface, not an implementation class.
    </para>

    <para>
      If the UserMapper has a corresponding MyBatis XML mapper file, it will be
      parsed automatically by the <literal>MapperFactoryBean</literal>.
      There is no need to include the <literal>&lt;mappers&gt;</literal> 
      section in the MyBatis configuration file. 
      Remember that mapper XML file <emphasis>must</emphasis> be in the same classpath 
{'fraction_non_alphanumeric': 0.08381757351646417, 'fraction_numerical': 0.005282620179609086, 'mean_word_length': 3.5954692556634305, 'pattern_counts': {'":': 0, '<': 87, '<?xml version=': 2, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1035819', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1492, 'n_words': 635}