blob: 30832cf927a2ba79839e2d8fb6f43e030ef68eba [file] [log] [blame]
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1382082-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-61232409-1');
</script>
<meta charset="UTF-8">
<title>Apache Ignite With Spring Boot | Ignite Documentation</title>
<link rel="canonical" href="/docs/spring/spring-boot" />
<link rel="stylesheet" href="/assets/css/styles.css?1658382975">
<link rel="stylesheet" href="/assets/css/asciidoc-pygments.css">
<link rel="shortcut icon" href="/favicon.ico">
<meta name='viewport' content='width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0'>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="/assets/js/jquery.swiftype.autocomplete.js?1658382975"></script>
<script type="text/javascript" src="/assets/js/anchor.min.js?1658382975"></script>
</head>
<body>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<header>
<!--#include virtual="/includes/promotion_banner.html" -->
<div class="container">
<button type='button' class='menu' title='Docs menu'>
<img src="{{'assets/images/menu-icon.svg'|relative_url}}" width="18" height="12" alt="menu icon" />
</button>
<div class='home'>
<a href="/" class='home' title='Apache Ignite home'>
<img src="{{'assets/images/apache_ignite_logo.svg'|relative_url}}" alt="Apache Ignite logo" width="103" height="36" >
</a>
</div>
<form class='search'>
<button class="search-close" type='button'><img src='{{"assets/images/cancel.svg"|relative_url}}' alt="close" width="10" height="10" /></button>
<input type="search" placeholder="Search…" id="search-input">
</form>
<button type='button' class='top-nav-toggle'></button>
</div>
</header>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<link rel="stylesheet" href="/assets/css/docs.css">
<section class='page-docs'>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<nav class='left-nav' data-swiftype-index='false'>
<li>
<a href="/docs/extensions/aws/aws" class=''>Amazon S3 IP Finder</a>
</li>
<li>
<a href="/docs/extensions/camel/camel-streamer" class=''>Apache Camel Streamer</a>
</li>
<li>
<a href="/docs/extensions/flink/flink-streamer" class=''>Apache Flink Streamer</a>
</li>
<li>
<a href="/docs/extensions/flume/flume-sink" class=''>Apache Flume Sink</a>
</li>
<li>
<a href="/docs/extensions/azure/azure" class=''>Apache Ignite Azure Module</a>
</li>
<li>
<a href="/docs/extensions/gce/gce" class=''>Apache Ignite GCE Module</a>
</li>
<li>
<a href="/docs/extensions/pub-sub/pub-sub" class=''>Apache Ignite Pub/Sub Module</a>
</li>
<li>
<a href="/docs/extensions/spring/spring-boot" class=''>Apache Ignite and Spring Boot</a>
</li>
<li>
<a href="/docs/extensions/spring/spring-data" class=''>Apache Ignite and Spring Data</a>
</li>
<li>
<a href="/docs/extensions/spring/spring-caching" class=''>Apache Ignite and Spring Cache</a>
</li>
<li>
<a href="/docs/extensions/spring/spring-sessions" class=''>Apache Ignite and Spring Session</a>
</li>
<li>
<a href="/docs/extensions/spring/spring-tx" class=''>Apache Ignite and Spring Transactions</a>
</li>
<li>
<a href="/docs/extensions/kafka/kafka-streamer" class=''>Apache Kafka Streamer</a>
</li>
<li>
<a href="/docs/extensions/storm/storm-streamer" class=''>Apache Storm Streamer</a>
</li>
<li>
<a href="/docs/extensions/cdc/change-data-capture-extensions" class=''>Change Data Capture Extension</a>
</li>
<li>
<a href="/docs/extensions/jms/jms-streamer" class=''>JMS Streamer</a>
</li>
<li>
<a href="/docs/extensions/mqtt/mqtt-streamer" class=''>MQTT Streamer</a>
</li>
<li>
<a href="/docs/extensions/perf-statistics/performance-statistics" class=''>Performance Statistics Extension</a>
</li>
<li>
<a href="/docs/extensions/rocketmq/rocketmq-streamer" class=''>RocketMQ Streamer</a>
</li>
<li>
<a href="/docs/extensions/topology-validator/topology-validator" class=''>Topology Validator</a>
</li>
<li>
<a href="/docs/extensions/twitter/twitter-streamer" class=''>Twitter Streamer</a>
</li>
<li>
<a href="/docs/extensions/zeromq/zeromq-streamer" class=''>ZeroMQ Streamer</a>
</li>
<li>
<a href="/docs/extensions/zookeeper/zookeeper-ip" class=''>ZooKeeper IP Finder</a>
</li>
</nav>
<div class="left-nav__overlay"></div>
<article data-swiftype-index='true'>
<a class='edit-link' href="/_docs/spring/spring-boot.adoc" target="_blank">Edit</a>
<h1>Apache Ignite With Spring Boot</h1>
<div class="sect1">
<h2 id="overview">Overview</h2>
<div class="sectionbody">
<div class="paragraph">
<p><a href="https://spring.io/projects/spring-boot" target="_blank" rel="noopener">Spring Boot</a> is a widely used Java framework that makes it easy
to create stand-alone Spring-based applications.</p>
</div>
<div class="paragraph">
<p>Apache Ignite provides two extensions that automate Ignite configuration withing the Spring Boot environment:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>ignite-spring-boot-autoconfigure-ext</code> - autoconfigures ignite server and client nodes within Spring Boot.</p>
</li>
<li>
<p><code>ignite-spring-boot-thin-client-autoconfigure-ext</code> - autoconfigures <a href="/docs/extensions/thin-clients/java-thin-client">Ignite Thin Client</a> with Spring Boot.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="autoconfiguration-of-apache-ignite-servers-and-clients">Autoconfiguration of Apache Ignite Servers and Clients</h2>
<div class="sectionbody">
<div class="paragraph">
<p>You need to use <code>ignite-spring-boot-autoconfigure-ext</code> extension to autoconfigure Ignite servers or clients (aka. thick clients) with Spring Boot.</p>
</div>
<div class="paragraph">
<p>The extension can be added with Maven as follows:</p>
</div>
<code-tabs><code-tab data-tab='pom.xml'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="xml"><span class="nt">&lt;dependency&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.apache.ignite<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>ignite-spring-boot-autoconfigure-ext<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>1.0.0<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span></code></pre>
</div>
</div></code-tab></code-tabs>
<div class="paragraph">
<p>Once added, Spring will create an Ignite instance on start-up automatically.</p>
</div>
<div class="sect2">
<h3 id="set-ignite-up-via-spring-boot-configuration">Set Ignite Up Via Spring Boot Configuration</h3>
<div class="paragraph">
<p>You can use a regular Spring Boot configuration to set Ignite-specific settings. Use <code>ignite</code> as a prefix:</p>
</div>
<code-tabs><code-tab data-tab='application.yml'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"><span class="na">ignite</span><span class="pi">:</span>
<span class="na">igniteInstanceName</span><span class="pi">:</span> <span class="s">properties-instance-name</span>
<span class="na">communicationSpi</span><span class="pi">:</span>
<span class="na">localPort</span><span class="pi">:</span> <span class="m">5555</span>
<span class="na">dataStorageConfiguration</span><span class="pi">:</span>
<span class="na">defaultDataRegionConfiguration</span><span class="pi">:</span>
<span class="na">initialSize</span><span class="pi">:</span> <span class="m">10485760</span> <span class="c1">#10MB</span>
<span class="na">dataRegionConfigurations</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">my-dataregion</span>
<span class="na">initialSize</span><span class="pi">:</span> <span class="m">104857600</span> <span class="c1">#100MB</span>
<span class="na">cacheConfiguration</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">accounts</span>
<span class="na">queryEntities</span><span class="pi">:</span>
<span class="pi">-</span> <span class="na">tableName</span><span class="pi">:</span> <span class="s">ACCOUNTS</span>
<span class="na">keyFieldName</span><span class="pi">:</span> <span class="s">ID</span>
<span class="na">keyType</span><span class="pi">:</span> <span class="s">java.lang.Long</span>
<span class="na">valueType</span><span class="pi">:</span> <span class="s">java.lang.Object</span>
<span class="na">fields</span><span class="pi">:</span>
<span class="na">ID</span><span class="pi">:</span> <span class="s">java.lang.Long</span>
<span class="na">amount</span><span class="pi">:</span> <span class="s">java.lang.Double</span>
<span class="na">updateDate</span><span class="pi">:</span> <span class="s">java.util.Date</span>
<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">my-cache2</span></code></pre>
</div>
</div></code-tab></code-tabs>
</div>
<div class="sect2">
<h3 id="set-ignite-up-programmatically">Set Ignite Up Programmatically</h3>
<div class="paragraph">
<p>There are two ways to configure Ignite programmatically.</p>
</div>
<div class="paragraph">
<p><strong>1. Create IgniteConfiguration Bean</strong></p>
</div>
<div class="paragraph">
<p>Just create a method that returns <code>IgniteConfiguration</code> bean that will be used to initialize an Ignite node with the settings you set:</p>
</div>
<code-tabs><code-tab data-tab='Java'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="java"><span class="nd">@Bean</span>
<span class="kd">public</span> <span class="nc">IgniteConfiguration</span> <span class="nf">igniteConfiguration</span><span class="o">()</span> <span class="o">{</span>
<span class="c1">// If you provide a whole ClientConfiguration bean then configuration properties will not be used.</span>
<span class="nc">IgniteConfiguration</span> <span class="n">cfg</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">IgniteConfiguration</span><span class="o">();</span>
<span class="n">cfg</span><span class="o">.</span><span class="na">setIgniteInstanceName</span><span class="o">(</span><span class="s">"my-ignite"</span><span class="o">);</span>
<span class="k">return</span> <span class="n">cfg</span><span class="o">;</span>
<span class="o">}</span></code></pre>
</div>
</div></code-tab></code-tabs>
<div class="paragraph">
<p><strong>2. Customize IgniteConfiguration Created With Spring Boot Configuration</strong></p>
</div>
<div class="paragraph">
<p>If you want to customize <code>IgniteConfiguration</code> that was initially created with Spring Boot configuration file, then
provide an implementation of <code>IgniteConfigurer</code> interface for your application context.</p>
</div>
<div class="paragraph">
<p>First, <code>IgniteConfiguration</code> will be loaded from the Spring Boot configuration and then that instance will be passed to the configurer for extra settings.</p>
</div>
<code-tabs><code-tab data-tab='Java'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="java"><span class="nd">@Bean</span>
<span class="kd">public</span> <span class="nc">IgniteConfigurer</span> <span class="nf">nodeConfigurer</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">cfg</span> <span class="o">-&gt;</span> <span class="o">{</span>
<span class="c1">//Setting some property.</span>
<span class="c1">//Other will come from `application.yml`</span>
<span class="n">cfg</span><span class="o">.</span><span class="na">setIgniteInstanceName</span><span class="o">(</span><span class="s">"my-ignite"</span><span class="o">);</span>
<span class="o">};</span>
<span class="o">}</span></code></pre>
</div>
</div></code-tab></code-tabs>
</div>
</div>
</div>
<div class="sect1">
<h2 id="autoconfiguration-of-apache-ignite-thin-client">Autoconfiguration of Apache Ignite Thin Client</h2>
<div class="sectionbody">
<div class="paragraph">
<p>You need to use <code>ignite-spring-boot-thin-client-autoconfigure-ext</code> extension to autoconfigure Ignite Thin Client with Spring Boot.</p>
</div>
<code-tabs><code-tab data-tab='pom.xml'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="xml"><span class="nt">&lt;dependency&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.apache.ignite<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>ignite-spring-boot-thin-client-autoconfigure-ext<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>1.0.0<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span></code></pre>
</div>
</div></code-tab></code-tabs>
<div class="paragraph">
<p>Once added, Spring will create an instance of Ignite Thin client connection on start-up automatically.</p>
</div>
<div class="sect2">
<h3 id="set-thin-client-up-via-spring-boot-configuration">Set Thin Client Up Via Spring Boot Configuration</h3>
<div class="paragraph">
<p>You can use a regular Spring Boot configuration to configure <code>IgniteClient</code> object. Use <code>ignite-client</code> for Ignite-specific settings:</p>
</div>
<code-tabs><code-tab data-tab='application.yml'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="yaml"><span class="na">ignite-client</span><span class="pi">:</span>
<span class="na">addresses</span><span class="pi">:</span> <span class="s">127.0.0.1:10800</span> <span class="c1"># this is mandatory property!</span>
<span class="na">timeout</span><span class="pi">:</span> <span class="m">10000</span>
<span class="na">tcpNoDelay</span><span class="pi">:</span> <span class="no">false</span></code></pre>
</div>
</div></code-tab></code-tabs>
</div>
<div class="sect2">
<h3 id="set-thin-client-up-programmatically">Set Thin Client Up Programmatically</h3>
<div class="paragraph">
<p>You can use two ways to configure <code>IgniteClient</code> object programmatically.</p>
</div>
<div class="paragraph">
<p><strong>1. Create ClientConfiguration bean</strong></p>
</div>
<div class="paragraph">
<p>Just create a method that returns <code>ClientConfiguration</code> bean. <code>IgniteClient</code> object will use that bean upon startup:</p>
</div>
<code-tabs><code-tab data-tab='Java'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="java"><span class="nd">@Bean</span>
<span class="kd">public</span> <span class="nc">ClientConfiguration</span> <span class="nf">clientConfiguration</span><span class="o">()</span> <span class="o">{</span>
<span class="c1">// If you provide a whole ClientConfiguration bean then configuration properties will not be used.</span>
<span class="nc">ClientConfiguration</span> <span class="n">cfg</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">ClientConfiguration</span><span class="o">();</span>
<span class="n">cfg</span><span class="o">.</span><span class="na">setAddresses</span><span class="o">(</span><span class="s">"127.0.0.1:10800"</span><span class="o">);</span>
<span class="k">return</span> <span class="n">cfg</span><span class="o">;</span>
<span class="o">}</span></code></pre>
</div>
</div></code-tab></code-tabs>
<div class="paragraph">
<p><strong>2. Customize ClientConfiguration Created With Spring Boot Configuration</strong></p>
</div>
<div class="paragraph">
<p>If you want to customize <code>ClientConfiguration</code> bean created from the Spring Boot configuration file, then provide an
implementation of <code>IgniteClientConfigurer</code> interface in your application context.</p>
</div>
<div class="paragraph">
<p>First, <code>ClientConfiguration</code> will be loaded from the Spring Boot configuration and then an instance will be passed to the configurer.</p>
</div>
<code-tabs><code-tab data-tab='Java'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="java"><span class="nd">@Bean</span>
<span class="nc">IgniteClientConfigurer</span> <span class="nf">configurer</span><span class="o">()</span> <span class="o">{</span>
<span class="c1">//Setting some property.</span>
<span class="c1">//Other will come from `application.yml`</span>
<span class="k">return</span> <span class="n">cfg</span> <span class="o">-&gt;</span> <span class="n">cfg</span><span class="o">.</span><span class="na">setSendBufferSize</span><span class="o">(</span><span class="mi">64</span><span class="o">*</span><span class="mi">1024</span><span class="o">);</span>
<span class="o">}</span></code></pre>
</div>
</div></code-tab></code-tabs>
</div>
</div>
</div>
<div class="sect1">
<h2 id="examples">Examples</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Refer to several available <a href="https://github.com/apache/ignite-extensions/tree/master/modules/spring-boot-autoconfigure-ext/examples/main">examples</a>
for more details.</p>
</div>
</div>
</div>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<div class="copyright">
© 2022 The Apache Software Foundation.<br/>
Apache, Apache Ignite, the Apache feather and the Apache Ignite logo are either registered trademarks or trademarks of The Apache Software Foundation.
</div>
</article>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<nav class="right-nav" data-swiftype-index='false'>
<ul class="sectlevel1">
<li><a href="#overview">Overview</a></li>
<li><a href="#autoconfiguration-of-apache-ignite-servers-and-clients">Autoconfiguration of Apache Ignite Servers and Clients</a>
<ul class="sectlevel2">
<li><a href="#set-ignite-up-via-spring-boot-configuration">Set Ignite Up Via Spring Boot Configuration</a></li>
<li><a href="#set-ignite-up-programmatically">Set Ignite Up Programmatically</a></li>
</ul>
</li>
<li><a href="#autoconfiguration-of-apache-ignite-thin-client">Autoconfiguration of Apache Ignite Thin Client</a>
<ul class="sectlevel2">
<li><a href="#set-thin-client-up-via-spring-boot-configuration">Set Thin Client Up Via Spring Boot Configuration</a></li>
<li><a href="#set-thin-client-up-programmatically">Set Thin Client Up Programmatically</a></li>
</ul>
</li>
<li><a href="#examples">Examples</a></li>
</ul>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<footer>
</footer>
</nav>
</section>
<script type='module' src='/assets/js/code-copy-to-clipboard.js' async></script>
<script>
// inits deep anchors -- needs to be done here because of https://www.bryanbraun.com/anchorjs/#dont-run-it-too-late
anchors.add('.page-docs h1, .page-docs h2, .page-docs h3:not(.discrete), .page-docs h4, .page-docs h5');
anchors.options = {
placement: 'right',
visible: 'always'
};
</script>
</body>
<script type='module' src='/assets/js/index.js?1658382975' async></script>
</html>