可能大家都能跑通的ignite的HelloWorld
生活随笔
收集整理的這篇文章主要介紹了
可能大家都能跑通的ignite的HelloWorld
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
ignite的開發(fā),說難很難,說簡單也很簡單,開頭第一個小程序,一定是HelloWorld。
下面開始HelloWorld
開發(fā)環(huán)境的配置,我是使用Spring+SpringMVC+MyBatis+Maven搭建的,如果有小伙伴不會搭建的話…留言表示一下,如果需要的話,我就寫個搭建SSM教程好了,雖然網(wǎng)上很多SSM的搭建的教程,但是,反正我剛開始的時候,幾乎大家的教程都不能用(黑臉)好了,廢話不多說了。
首先,maven中添加依賴,如下:(我懶了,我直接把項目中所有的maven配置拷過來了,請自行刪減)
<dependencies><!-- 單元測試 --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version></dependency><!-- 1.日志 --><!-- 實現(xiàn)slf4j接口并整合 --><dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>1.1.1</version></dependency><!-- 2.數(shù)據(jù)庫 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.37</version><scope>runtime</scope></dependency><dependency><groupId>c3p0</groupId><artifactId>c3p0</artifactId><version>0.9.1.2</version></dependency><!-- DAO: MyBatis --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.3.0</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>1.2.3</version></dependency><!-- 3.Servlet web --><dependency><groupId>taglibs</groupId><artifactId>standard</artifactId><version>1.1.2</version></dependency><dependency><groupId>jstl</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.5.4</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version></dependency><!-- 4.Spring --><!-- 1)Spring核心 --><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>4.1.7.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>4.1.7.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.1.7.RELEASE</version></dependency><!-- 2)Spring DAO層 --><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>4.1.7.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>4.1.7.RELEASE</version></dependency><!-- 3)Spring web --><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>4.1.7.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>4.1.7.RELEASE</version></dependency><!-- 4)Spring test --><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>4.1.7.RELEASE</version></dependency><!-- redis客戶端:Jedis --><dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>2.7.3</version></dependency><dependency><groupId>com.dyuproject.protostuff</groupId><artifactId>protostuff-core</artifactId><version>1.0.8</version></dependency><dependency><groupId>com.dyuproject.protostuff</groupId><artifactId>protostuff-runtime</artifactId><version>1.0.8</version></dependency><!-- Map工具類 --><dependency><groupId>commons-collections</groupId><artifactId>commons-collections</artifactId><version>3.2</version></dependency><!--JSCH用于通過SSH連接遠程主機--><dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.54</version></dependency><!-- ignite的依賴 --><dependency><groupId>org.apache.ignite</groupId><artifactId>ignite-core</artifactId><version>2.3.0</version></dependency><dependency><groupId>org.apache.ignite</groupId><artifactId>ignite-spring</artifactId><version>2.3.0</version></dependency><dependency><groupId>org.apache.ignite</groupId><artifactId>ignite-indexing</artifactId><version>2.3.0</version></dependency></dependencies>OK,下面,寫java代碼
public void helloworld(){try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {// 調(diào)用ignite方法向cache中創(chuàng)建鍵值對類型IgniteCache<Integer, String> firstTestcache = ignite.getOrCreateCache("firstTestCache");// 初始化鍵值對firstTestcache.put(1, "Hello");firstTestcache.put(2, "World!");// 從cache中根據(jù)鍵獲取值,并且向集群中的所有節(jié)點發(fā)出廣播ignite.compute().broadcast(() -> {String s1 = firstTestcache.get(1);String s2 = firstTestcache.get(2);System.out.println("cache 中的數(shù)據(jù):" + s1 + " " + s2);});}}OK了,隨便建個類,寫個main入口,直接跑上面的幾行代碼,即可在控制臺中打印出令人激動的HelloWorld
HelloWorld完成了,更深入的使用方法,后續(xù)再說……
總結(jié)
以上是生活随笔為你收集整理的可能大家都能跑通的ignite的HelloWorld的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Apache Ignite与Apache
- 下一篇: Ignite 的helloworld第二