today I'm trying to use spring to initialize some Geode compnents. The xml I created is like below:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
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
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd">
<beans>
<gfe:client-cache id="my-cache" pool-name="my-pool"/>
<gfe:pool id="my-pool" subscription-enabled="true">
<gfe:locator host="max" port="10334"/>
</gfe:pool>
</beans>
</beans>
I'm simply tring to get a client cache of Geode. When I run the code below :
public class GeodeLauncher {
public static void main(String[] args){
ApplicationContext ac = new FileSystemXmlApplicationContext("classpath:geodeConfig.xml");
ac.getBean("my-cache");
}
}
Exception throws:
Caused by: java.lang.ClassNotFoundException: com.gemstone.gemfire.distributed.DistributedSystem
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 31 more
I have added dependency in my pom.xml
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-core</artifactId>
<version>1.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-gemfire -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-geode</artifactId>
<version>1.0.0.APACHE-GEODE-INCUBATING-M2</version>
</dependency>
and I noticed that there's a same name class called DistributedSystem under package org.apache.geode.distributed.
Is this class supposed to be used? Why com.gemstone.gemfire.distributed.DistributedSystem is needed ? Did I config the xml wrong?
Yeah, you have a few version issues going on here.
First, Spring Data Geode 1.0.0.INCUBATING-RELEASE
is available (see release announcement as well), so you should update your application dependency to...
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-geode</artifactId>
<version>1.0.0.INCUBATING-RELEASE</version>
</dependency>
Second, there is not currently a version of Spring Data Geode that is officially based on the latest release of Apache Geode (i.e. 1.1.0) yet. Technically, SD Geode 1.0.0.INCUBATING-RELEASE was based on Apache Geode 1.0.0-incubating (the GA release right before Geode 1.1.0). I am planning a Spring Data Geode 1.1.0.RELEASE
soon, which will be based on Apache Geode 1.1.0.
However, though I do not officially support it, I think it is possible to update SDG 1.0.0.INCUBATING-RELEASE to use Apache Geode 1.1.0, and SDG will run just fine with Apache Geode 1.1.0 as well.
To do so, just declare the following dependencies in your application POM (at least until SDG 1.1.0.RELEASE is released ;-)...
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-geode</artifactId>
<version>1.0.0.INCUBATING-RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.apache.geode</groupId>
<artifact>geode-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.geode</groupId>
<artifact>geode-cq</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.geode</groupId>
<artifact>geode-wan</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-core</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-cq</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-wan</artifactId>
<version>1.1.0</version>
</dependency>
Prior to Apache Geode 1.0.0-incubating (i.e. Milestone releases), the package namespace for Geode classes were still rooted in com.gemstone.gemfire
(as Apache Geode originates from Pivotal GemFire).
However, as of Apache Geode 1.0.0-incubating and later (i.e. 1.1.0) the package namespace changed to org.apache.geode
. As such, you need a Spring Data Geode release that is compatible, which is currently 1.0.0.INCUBATING-RELEASE
.
Also note, your additional nested <beans>
tag in your Spring XML configuration file is unnecessary; your XML configuration can just be...
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
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
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd">
<gfe:client-cache id="my-cache" pool-name="my-pool"/>
<gfe:pool id="my-pool" subscription-enabled="true">
<gfe:locator host="max" port="10334"/>
</gfe:pool>
</beans>
Additionally, there is a general movement in Spring to move away from XML.
Starting in Spring Data Geode 1.0.0.APACHE-GEODE-INCUBATING-M3 and presently in 1.0.0.INCUBATING-RELEASE, you can do the equivalent Spring XML config in Java using the new Annotation model (inspired mostly by Spring Boot), like so...
import ...;
@SpringBootApplication
@ClientCacheApplication(locators = { @ClientCacheApplication.Locator(host="max") }
class GeodeLauncher {
@Autowired
private ClientCache geodeClientCache;
public static void main(String[] args) {
SpringApplication.run(GeodeLauncher.class, args);
}
}
One final note, if you are on the real bleeding edge, you can always use build snapshots of Spring Data Geode 1.1.0.BUILD-SNAPSHOT, available in Spring's libs-snapshot
Maven Repository. You just need to add the appropriate repository declaration to your application POM file...
<repository>
<id>spring-libs-snapshot</id>
<url>https://repo.spring.io/libs-snapshot</url>
</repository>
Spring Data Geode 1.1.0.BUILD-SNAPSHOT
is based on Apache Geode 1.1.0.
Then, your dependency declaration simply becomes...
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-geode</artifactId>
<version>1.1.0.BUILD-SNAPSHOT</version>
</dependency>
Without all the exclusion business and explicit dependencies on Apache Geode 1.1.0 artifacts. The other nice thing is that SDG 1.1.0 includes support for Geode's Lucene Integration.
Anyway, hope this helps. You can always see more examples of different configuration styles in my SDG reference implementation (RI) GitHub project here...
There are many examples comparing Spring XML config (then here) to Geode cache.xml
, then Spring XML to Spring JavaConfig to using the new Annotation configuration model (and of course, the client-side using Annotations), etc, etc.
Cheers, John