|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"> |
| 3 | +<!-- |
| 4 | + Copyright 2010 The myBatis Team |
| 5 | +
|
| 6 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + you may not use this file except in compliance with the License. |
| 8 | + You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, software |
| 13 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + See the License for the specific language governing permissions and |
| 16 | + limitations under the License. |
| 17 | +--> |
| 18 | + |
| 19 | +<!-- |
| 20 | + version: $Id$ |
| 21 | +--> |
| 22 | +<chapter id="bootstrap"> |
| 23 | + <title>Bootstrap</title> |
| 24 | + |
| 25 | + <section id="bootstrap.intro"> |
| 26 | + <title>Introduction</title> |
| 27 | + <para> |
| 28 | + MyBatis-Spring integration helps you to integrate your code seamlessly with Spring. Spring will load and |
| 29 | + create necessary MyBatis classes for you. It will also inject working Mappers/Daos directly on your service |
| 30 | + beans. |
| 31 | + </para> |
| 32 | + </section> |
| 33 | + |
| 34 | + <section id="bootstrap.setup"> |
| 35 | + <title>Setting up a SqlSessionFactory</title> |
| 36 | + <para> |
| 37 | + As you already know, to use MyBatis you need to build a <literal>SqlSessionFactory</literal> from XML files. |
| 38 | + MyBatis-Spring will build a SqlSessionFactory for you during Spring startup. |
| 39 | + |
| 40 | + The XML snippet below shows the configuration needed to build a <literal>SqlSessionFactoryBean</literal>: |
| 41 | + |
| 42 | + <programlisting language="xml"><![CDATA[<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> |
| 43 | + <property name="dataSource" ref="dataSource" /> |
| 44 | + <property name="configLocation" value="classpath:sample/mybatis-config.xml" /> |
| 45 | +</bean>]]></programlisting> |
| 46 | + |
| 47 | + Where <literal>mybatis-config.xml</literal> is the main configuration file for MyBatis. |
| 48 | + Follows below a <literal>mybatis-config.xml</literal> sample, but please refeer to the MyBatis reference |
| 49 | + manual to know more details about it: |
| 50 | + |
| 51 | + <programlisting language="xml"><![CDATA[<configuration> |
| 52 | +
|
| 53 | + <settings> |
| 54 | + <setting name="cacheEnabled" value="false" /> |
| 55 | + <setting name="useGeneratedKeys" value="true" /> |
| 56 | + <setting name="defaultExecutorType" value="REUSE" /> |
| 57 | + </settings> |
| 58 | +
|
| 59 | + <mappers> |
| 60 | + <mapper resource="sample/UserMapper.xml" /> |
| 61 | + </mappers> |
| 62 | +
|
| 63 | +</configuration>]]></programlisting> |
| 64 | + </para> |
| 65 | + |
| 66 | + Usually the main config file holds general configuration options and the mappers list. The mappers list is |
| 67 | + optional if you are using injected mappers. |
| 68 | + </section> |
| 69 | + |
| 70 | +</chapter> |
0 commit comments