Files
spring-data-geode/docs/src/reference/docbook/reference/bootstrap.xml

212 lines
9.6 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<chapter version="5.0" xml:id="bootstrap"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xi="http://www.w3.org/2001/XInclude">
<title>Bootstrapping GemFire through the Spring Container</title>
<para>
Spring Data GemFire provides full configuration and initialization of the GemFire data grid through
Spring's IoC container and provides several classes that simplify the configuration of GemFire components
including Caches, Regions, WAN Gateways, Persistence Backup, and other Distributed System components
to support a variety of scenarios with minimal effort.
</para>
<note>
<para>
This section assumes basic familiarity with GemFire. For more information see the
<link xlink:href="http://www.vmware.com/products/application-platform/vfabric-gemfire">product</link>
documentation.
</para>
</note>
<section id="bootstrap:region:spring:config">
<title>Advantages of using Spring over GemFire
<literal>cache.xml</literal></title>
<para xmlns="">As of release 1.2.0, Spring Data GemFire's XML namespace
supports full configuration of the data grid. In fact, the Spring Data
GemFire namespace is considered the preferred way to configure GemFire.
GemFire will continue to support native <filename>
<literal xmlns="http://docbook.org/ns/docbook">cache.xml</literal>
</filename> for legacy reasons, but you can now do everything in Spring
XML and take advantage of the many wonderful things Spring has to offer
such as modular XML configuration, property placeholders, SpEL, and
environment profiles. Behind the namespace, Spring Data GemFire makes
extensive use of Spring's <interfacename>FactoryBean</interfacename>
pattern to simplify the creation and initialization of GemFire
components.</para>
<para xmlns=""> For example, GemFire provides several callback interfaces
such as <interfacename>
<literal xmlns="http://docbook.org/ns/docbook">CacheListener, </literal>
</interfacename><interfacename>
<literal xmlns="http://docbook.org/ns/docbook">CacheWriter, </literal>
</interfacename>and<interfacename>
<literal xmlns="http://docbook.org/ns/docbook">CacheLoader</literal>
</interfacename> to allow developers to add custom event handlers. Using
the Spring IoC container, these may configured as normal Spring beans and
injected into GemFire components. This is a significant improvement over
native <literal xmlns="http://docbook.org/ns/docbook">cache.xml</literal>
which provides relatively limited configuration options and requires
callbacks to implement GemFire's <literal>
<literal xmlns="http://docbook.org/ns/docbook">Declarable</literal>
</literal> interface (see <xref linkend="apis:declarable"
xmlns="http://docbook.org/ns/docbook"/> to see how you can still use
<literal xmlns="http://docbook.org/ns/docbook">Declarables</literal>
within Spring's DI container).</para>
<para xmlns=""> In addition, IDEs such as the Spring Tool Suite (STS)
provide excellent support for Spring XML namespaces, such as code
completion, pop-up annotations, and real time validation, making them easy
to use.</para>
</section>
<section id="bootstrap:namespace">
<title>Using the Core Spring Data GemFire Namespace</title>
<para>To simplify configuration, Spring Data GemFire provides a dedicated
XML namespace for configuring core GemFire components. It is also possible
to configure the beans directly through Spring's standard &lt;bean&gt;
definition. However, as of Spring Data GemFire 1.2.0, all bean properties
are exposed via the namespace so there is little benefit to using raw bean
definitions. For more information about XML Schema-based configuration in
Spring, see <ulink
url="http://static.springsource.org/spring/docs/current/spring-framework-reference/html/xsd-config.html">this</ulink>
appendix in the Spring Framework reference documentation.</para>
<note>
<para>Spring Data Repository support uses a separate XML namespace. See
<xref linkend="gemfire-repositories"/> for more information on how to
configure GemFire Repositories.</para>
</note>
<para>To use the Spring Data GemFire namespace, simply declare it in your
Spring XML configuration meta-data:</para>
<programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlxsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:<co id="gfe#ns#prefix"/>gfe="http://www.springframework.org/schema/gemfire"<co
id="gfe#ns#uri"/>
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
<co id="gfe#ns#uri#loc"/>http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd"&gt;
&lt;bean id ... &gt;
<co id="gfe#ns#example"/>&lt;gfe:cache ...&gt;
&lt;/beans&gt;</programlisting>
<calloutlist>
<callout arearefs="gfe#ns#prefix">
<para>Spring GemFire namespace prefix. Any name will do but through
out the reference documentation, <literal>gfe</literal> will be
used.</para>
</callout>
<callout arearefs="gfe#ns#uri">
<para>The namespace URI.</para>
</callout>
<callout arearefs="gfe#ns#uri#loc">
<para>The namespace URI location. Note that even though the location
points to an external address (which exists and is valid), Spring will
resolve the schema locally as it is included in the Spring Data
GemFire library.</para>
</callout>
<callout arearefs="gfe#ns#example">
<para>Declaration example for the GemFire namespace. Notice the prefix
usage.</para>
</callout>
</calloutlist>
<para>Once declared, the namespace elements can be declared simply by
appending the aforementioned prefix.</para>
<note>
<para>It is possible to change the default namespace, for example from
<literal>beans</literal> to <literal>gfe</literal>. This is useful for
configuration composed mainly of GemFire components as it avoids
declaring the prefix. To achieve this, simply swap the namespace prefix
declaration above:</para>
<programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="<co id="gfe#default-ns#prefix"/>http://www.springframework.org/schema/gemfire"
xmlxsi="http://www.w3.org/2001/XMLSchema-instance"
<co id="gfe#default-ns#beans-prefix"/>
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd"&gt;
<co id="gfe#default-ns#beans-example"/>&lt;beans:bean id ... &gt;
<co id="gfe#default-ns#gfe-example"/>&lt;cache ...&gt;
&lt;/beans&gt;</programlisting>
<calloutlist>
<callout arearefs="gfe#default-ns#prefix">
<para>The default namespace declaration for this XML file points to
the Spring Data GemFire namespace.</para>
</callout>
<callout arearefs="gfe#default-ns#beans-prefix">
<para>The beans namespace prefix declaration.</para>
</callout>
<callout arearefs="gfe#default-ns#beans-example">
<para>Bean declaration using the <literal>beans</literal> namespace.
Notice the prefix.</para>
</callout>
<callout arearefs="gfe#default-ns#gfe-example">
<para>Bean declaration using the <literal>gfe</literal> namespace.
Notice the lack of prefix (as the default namespace is used).</para>
</callout>
</calloutlist>
</note>
</section>
<xi:include href="cache.xml"/>
<xi:include href="data-access.xml"/>
<xi:include href="region.xml"/>
<section id="bootstrap:indicies">
<title>Creating an Index</title>
<para>GemFire allows creation on indexes (or indices) to improve the
performance of (common) queries. Spring Data GemFire allows indecies to be
declared through the <literal>index</literal> element:</para>
<programlisting language="xml">&lt;gfe:index id="myIndex" expression="someField" from="/someRegion"/&gt;</programlisting>
<para>Before creating an index, Spring Data GemFire will verify whether
one with the same name already exists. If it does, it will compare the
properties and if they don't match, will remove the old one to create a
new one. If the properties match, Spring Data GemFire will simply return
the index (in case it does not exist it will simply create one). To
prevent the update of the index, even if the properties do not match, set
the property <literal>override</literal> to false.</para>
<para>Note that index declaration are not bound to a region but rather are
top-level elements (just like <literal>gfe:cache</literal>). This allows
one to declare any number of indecies on any region whether they are just
created or already exist - an improvement versus the GemFire
<literal>cache.xml</literal>. By default the index relies on the default
cache declaration but one can customize it accordingly or use a pool (if
need be) - see the namespace schema for the full set of options.</para>
</section>
<xi:include href="diskstore.xml"/>
<xi:include href="function.xml"/>
<xi:include href="gateway.xml"/>
</chapter>