IGNITE-8641: Spring data example now uses its own xml config (#7280)
diff --git a/examples/config/spring/example-spring-data.xml b/examples/config/spring/example-spring-data.xml
new file mode 100644
index 0000000..6a37d9e
--- /dev/null
+++ b/examples/config/spring/example-spring-data.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!--
+ Ignite Spring configuration file to startup Ignite cache.
+
+ This file demonstrates how to configure cache using Spring. Provided cache
+ will be created on node startup.
+
+ Use this configuration file when running Spring Data examples (see 'examples/springdata' folder).
+
+ When starting a standalone node, you need to execute the following command:
+ {IGNITE_HOME}/bin/ignite.{bat|sh} examples/config/spring/example-spring-data.xml
+
+ When starting Ignite from Java IDE, pass path to this file to Ignition:
+ Ignition.start("examples/config/spring/example-spring-data.xml");
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+ <!-- Imports default Ignite configuration -->
+ <import resource="../example-default.xml"/>
+
+ <bean parent="ignite.cfg">
+ <property name="igniteInstanceName" value="springDataNode" />
+
+ <property name="cacheConfiguration">
+ <list>
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <!--
+ Apache Ignite uses an IgniteRepository extension which inherits from Spring Data's CrudRepository.
+ The SQL grid is also enabled to aceess Spring Data repository. The @RepositoryConfig annotation
+ maps the PersonRepository to an Ignite's cache named "PersonCache".
+ -->
+ <property name="name" value="PersonCache"/>
+ <property name="indexedTypes">
+ <list>
+ <value>java.lang.Long</value>
+ <value>org.apache.ignite.examples.model.Person</value>
+ </list>
+ </property>
+ </bean>
+ </list>
+ </property>
+ </bean>
+</beans>
diff --git a/examples/src/main/java/org/apache/ignite/examples/springdata/SpringAppCfg.java b/examples/src/main/java/org/apache/ignite/examples/springdata/SpringApplicationConfiguration.java
similarity index 74%
rename from examples/src/main/java/org/apache/ignite/examples/springdata/SpringAppCfg.java
rename to examples/src/main/java/org/apache/ignite/examples/springdata/SpringApplicationConfiguration.java
index 78f2085..7d415e0 100644
--- a/examples/src/main/java/org/apache/ignite/examples/springdata/SpringAppCfg.java
+++ b/examples/src/main/java/org/apache/ignite/examples/springdata/SpringApplicationConfiguration.java
@@ -19,9 +19,7 @@
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.examples.model.Person;
import org.apache.ignite.springdata20.repository.IgniteRepository;
import org.apache.ignite.springdata20.repository.config.EnableIgniteRepositories;
import org.apache.ignite.springdata20.repository.support.IgniteRepositoryFactoryBean;
@@ -41,29 +39,13 @@
*/
@Configuration
@EnableIgniteRepositories
-public class SpringAppCfg {
+public class SpringApplicationConfiguration {
/**
* Creating Apache Ignite instance bean. A bean will be passed to {@link IgniteRepositoryFactoryBean} to initialize
* all Ignite based Spring Data repositories and connect to a cluster.
*/
@Bean
public Ignite igniteInstance() {
- IgniteConfiguration cfg = new IgniteConfiguration();
-
- // Setting some custom name for the node.
- cfg.setIgniteInstanceName("springDataNode");
-
- // Enabling peer-class loading feature.
- cfg.setPeerClassLoadingEnabled(true);
-
- // Defining and creating a new cache to be used by Ignite Spring Data repository.
- CacheConfiguration ccfg = new CacheConfiguration("PersonCache");
-
- // Setting SQL schema for the cache.
- ccfg.setIndexedTypes(Long.class, Person.class);
-
- cfg.setCacheConfiguration(ccfg);
-
- return Ignition.start(cfg);
+ return Ignition.start("examples/config/spring/example-spring-data.xml");
}
}
diff --git a/examples/src/main/java/org/apache/ignite/examples/springdata/SpringDataExample.java b/examples/src/main/java/org/apache/ignite/examples/springdata/SpringDataExample.java
index cd91bd3..f0bf7be 100644
--- a/examples/src/main/java/org/apache/ignite/examples/springdata/SpringDataExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/springdata/SpringDataExample.java
@@ -31,10 +31,10 @@
* The example demonstrates how to interact with an Apache Ignite cluster by means of Spring Data API.
*
* Additional cluster nodes can be started with special configuration file which
- * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
+ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/spring/example-spring-data.xml'}.
* <p>
* Alternatively you can run {@link ExampleNodeStartup} in another JVM which will
- * start an additional node with {@code examples/config/example-ignite.xml} configuration.
+ * start an additional node with {@code examples/config/spring/example-spring-data.xml} configuration.
*/
public class SpringDataExample {
/** Spring Application Context. */
@@ -74,7 +74,7 @@
ctx = new AnnotationConfigApplicationContext();
// Explicitly registering Spring configuration.
- ctx.register(SpringAppCfg.class);
+ ctx.register(SpringApplicationConfiguration.class);
ctx.refresh();