发表于: 2018-03-06 12:37:15

2 775


主要解决这个问题(找不到主方法)

 

接下来使用Junit来测试

(修改测试类)

package com.fuwei.util;

import junit.framework.Assert;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.test.context.ContextConfiguration;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**

* Created by ${MIND-ZR} on 2017/11/25.

*/

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration("classpath:applicationContext.xml")

public class MemcachedSpringTest {

@Test

public void testMemcached() {

MemcachedUtil.put("hello", "word", 60);

String hello = (String) MemcachedUtil.get("hello");

System.out.println("------------------------------------");

Assert.assertEquals("word", hello);

 

for (int i = 0; i < 100; i++) {

UserBean userBean = new UserBean("Jason" + i, "123456-" + i);

MemcachedUtil.put("user" + i, userBean, 60);

Object obj = MemcachedUtil.get("user" + i);

Assert.assertEquals(userBean, obj);

System.out.println(userBean);

 

}

}

}

 

运行结果为空

http://blog.csdn.net/xn_28/article/details/60588474(解决文档 )

重新构建项目出现问题

修改了了jar

换主函数测试

package com.fuwei.util;

 

import com.whalin.MemCached.MemCachedClient;

import com.whalin.MemCached.SockIOPool;

 

/**

* ClassName:MemcachedClient <br/>

* Function: Memcached客户端. <br/>

* Date: 2017222日 下午1:32:26 <br/>

* @author qiyongkang

* @version

* @since JDK 1.6

* @see

*/

public class MemcachedClient {

public static void main(String[] args) {

// 初始化SockIOPool,管理memcached的连接池

String[] servers = { "47.94.14.145:11211" };

SockIOPool pool = SockIOPool.getInstance();

pool.setServers(servers);

pool.setFailover(true);

pool.setInitConn(10);

pool.setMinConn(5);

pool.setMaxConn(250);

pool.setMaintSleep(30);

pool.setNagle(false);

pool.setSocketTO(3000);

pool.setAliveCheck(true);

pool.initialize();

// 建立MemcachedClient实例

MemCachedClient memCachedClient = new MemCachedClient();

// 将对象加入到memcached缓存

boolean success = memCachedClient.set("name", "qiyongkang");

// memcached缓存中按key值取对象

String result = (String) memCachedClient.get("name");

System.out.println(String.format("set:" + success));

System.out.println(String.format("get:" + result));

}

}

package com.fuwei.util;

import junit.framework.TestCase;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.test.context.ContextConfiguration;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

 

/**

* Created by ${MIND-ZR} on 2017/11/25.

*/

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration("classpath:applicationContext.xml")

public class MemcachedSpringTest {

 

 

@Test

public void testMemcached() {

MemcachedUtil.put("hello", "word", 60);

String hello = (String) MemcachedUtil.get("hello");

TestCase.assertEquals("word", hello);

 

for (int i = 0; i < 100; i++) {

UserBean userBean = new UserBean("Jason" + i, "123456-" + i);

MemcachedUtil.put("user" + i, userBean, 60);

Object obj = MemcachedUtil.get("user" + i);

TestCase.assertEquals(userBean, obj);

System.out.println(userBean);

 

}

}

}

终于解决啦

后面梳理一下知识点,这个卡了两天啦

(最近一直都在看memcached这个文档)

 

开始主要是

1.memcached.properties(具体端口等的配置)

2.memcachedContext.XML的详细配置

3.UserBean的实体类的实现

4.测试类的编写

上面就是简单的的memcached的知识点的梳理

准备查看接下的任务.但是官网的任务没有加载(只好先放一放)

今天完成的事情:终于把memcached的流程打通了,这个换成机制,感觉和spring的结合还是容易学习,前面的问题出现就是对这个流程不熟悉,后面查了几天的文档,和其他的博客,和许多的CSDN的一些技术分享的博客,终于熟悉这个memcached的流程.

今天遇到的困难:就是在弄那个memcached的测试的时候就是Junitjar,还有类的过时,怎么去解决这个问题,查询相关的文档来解决这个jar包里面的类过期的问题,开始一直还是认为是自己的类的问题,后面还是重构项目来解决的这个问题,才发现的这个问题,又学习了一种解决bug问题的方法.

明天的计划:继续完成接下来的memcached,部署服务器,在项目中的运用,测试的demo跑通了,就怎么添加到真实的项目中去应用

 

还是坚持开学了感觉这学期的课还是挺多的,每天坚持coding<师兄离开啦,欢迎新师兄的帮助和指导>

 



返回列表 返回列表
评论

    分享到