Skip to content
Browse files
IGNITE-13769 Adds examples of using thin client with spring-data-ext. (
  • Loading branch information
ololo3000 committed Mar 29, 2021
1 parent 1844edc commit 484a26f97ca7075ee314ce64fc45d4d812b816b1
Showing 2 changed files with 89 additions and 5 deletions.
@@ -0,0 +1,53 @@
* 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
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.

package org.apache.ignite.springdata20.examples;

import org.apache.ignite.Ignition;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.configuration.ClientConfiguration;
import org.apache.ignite.springdata20.repository.config.EnableIgniteRepositories;
import org.apache.ignite.springdata20.repository.config.RepositoryConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static org.apache.ignite.configuration.ClientConnectorConfiguration.DFLT_PORT;

* Example of Spring application configuration that represents beans required to configure Spring Data repository access
* to an Ignite cluster through the thin client.
* Note that both Ignite thin client and Ignite node approaches of Ignite cluster access configuration uses the same API.
* Ignite Spring Data integration automatically recognizes the type of provided bean and use the appropriate
* cluster connection.
* @see SpringApplicationConfiguration
public class IgniteClientSpringApplicationConfiguration {
* Creates Apache Ignite thin client instance bean which will be used for accessing the Ignite cluster.
* Note, that the name of the current bean must match value of {@link RepositoryConfig#igniteInstance}
* property that {@link PersonRepository} is marked with. In this particular case, the default value of
* {@link RepositoryConfig#igniteInstance} property is used.
public IgniteClient igniteInstance() {
return Ignition.startClient(new ClientConfiguration().setAddresses("" + DFLT_PORT));
@@ -22,6 +22,10 @@
import java.util.List;
import java.util.TreeMap;
import javax.cache.Cache;
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.springdata20.examples.model.Person;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -40,12 +44,37 @@ public class SpringDataExample {
private static PersonRepository repo;

* Executes the example.
* Execute examples involving both approaches to configure Spring Data repository access to an Ignite cluster:
* through Ignite thin client and through Ignite node.
* @param args Command line arguments, none required.
public static void main(String[] args) {
// Initializing Spring Data context and Ignite repository.
try (Ignite ignored = startIgniteNode()) {
// Ignite node instance is used to configure access to the Ignite cluster.

// Ignite thin client instance is used to configure access to the Ignite cluster.

/** Starts an Ignite node that simulates an Ignite cluster to which Spring Data repository will perform access. */
private static Ignite startIgniteNode() {
IgniteConfiguration cfg = new IgniteConfiguration()
.setCacheConfiguration(new CacheConfiguration<Long, Person>("PersonCache")
.setIndexedTypes(Long.class, Person.class));

return Ignition.start(cfg);

* Performs basic Spring Data repository operation.
* @param springAppCfg Class of Spring application configuration that will be used for Spring context initialization.
private static void doSpringDataExample(Class<?> springAppCfg) {


@@ -65,12 +94,14 @@ public static void main(String[] args) {

* Initializes Spring Data and Ignite repositories.
* @param springAppCfg Class of Spring application configuration that will be used for Spring context initialization.
private static void igniteSpringDataInit() {
private static void igniteSpringDataInit(Class<?> springAppCfg) {
ctx = new AnnotationConfigApplicationContext();

// Explicitly registering Spring configuration.


0 comments on commit 484a26f

Please sign in to comment.