发表于: 2018-05-20 21:04:35

1 1437


今天完成的事情:(一定要写非常细致的内容,比如说学会了盒子模型,了解了Margin) 

由于之前404 也没有报错信息 重置了下我的test6 然后使用了xmemcache 方式

private  MemcachedClient memcachedClient;

public MemcachedClient getMemcachedClient() {
return memcachedClient;
}

public void setMemcachedClient(MemcachedClient memcachedClient) {
this.memcachedClient = memcachedClient;
}

使用setter 的依赖注入方式

然后报错空指针

测试了一下

public class XMemcachedSpring {
private ApplicationContext app;
private MemcachedClient memcachedClient;
@Before
   public void init() {
app = new ClassPathXmlApplicationContext("applicationContext.xml");
memcachedClient = (MemcachedClient) app.getBean("memcachedClient");
}
@Test
   public void test() {
try {
String i;

// 设置/获取
           memcachedClient.set("zlex", 36000, "set/get");
i=memcachedClient.get("zlex");
System.out.println(i);
// 替换
           memcachedClient.replace("zlex", 36000, "replace");
i=memcachedClient.get("zlex");
System.out.println(i);

// 移除
           memcachedClient.delete("zlex");
i=memcachedClient.get("zlex");
System.out.println(i);
} catch (Exception e) {
e.printStackTrace();
}
}

完全ok 

那么可能是注入方式的问题 

然后我修改成了getBean()方法

private static ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
private static MemcachedClient memcachedClient = (MemcachedClient) app.getBean("memcachedClient");

自己从Spring context中获取bean进行操作

这里复习了一下各种注入方式

(1)构造方法注入:即被注入对象可以通过在其构造方法中声明依赖对象的参数列表,让外部(通常是IOC容器)知道它需要哪些依赖对象,然后IOC容器会检查被注入对象的构造方法, 
取得其所需要的依赖对象列表,进而为其注入相应对象。

(2)setter方法注入:即当前对象只需要为其依赖对象所对应的属性添加setter方法,IOC容器通过此setter方法将相应的依赖对象设置到被注入对象的方式即setter方法注入。

(3)接口注入:接口注入有点复杂,被注入对象如果想要IOC容器为其注入依赖对象,就必须实现某个接口,这个接口提供一个方法,用来为被注入对象注入依赖对象,IOC容器通过接口方法将依赖对象注入到被注入对象中去。相对于前两种注入方式,接口注入比繁琐和死板,被注入对象就必须专声明和实现另外的接口。

基础不够 还是要回去看一下


然后报错

java.lang.IllegalArgumentException: Non-serializable object

没有序列化。。

这里出现了一个不熟悉的词 序列化 

Serializable 作用 

序列化的attribute,是为了利用序列化的技术
准备用于序列化的对象必须设置 [System.Serializable] 标签,该标签指示一个类可以序列化。
便于在网络中传输和保存

这个标签是类可以被序列化的特性,表示这个类可以被序列化。
什么叫序列化?
我们都知道对象是暂时保存在内存中的,不能用U盘考走了,有时为了使用介质转移对象,并且把对象的状态保持下来,就需要把对象保存下来,这个过程就叫做序列化,通俗点,就是把人的魂(对象)收伏成一个石子(可传输的介质)
什么叫反序列化?
就是再把介质中的东西还原成对象,把石子还原成人的过程。
在进行这些操作的时候都需要这个可以被序列化,要能被序列化,就得给类头加[Serializable]特性。
通常网络程序为了传输安全才这么做。

在pojo类里添加

public class User implements Serializable {
private static final long serialVersionUID = 5855771380992917716L;

序列化回头看 先继续做

测试也跑通了 

做到这里发现 打算明天复习一下依赖注入


感谢我的师兄们

用Jmeter测试了下

这是有缓存的

这是无缓存版的


性能提升还是很明显的 吞吐量差了近3倍

响应时间也差了很多

然后有一个问题 越到后面 越慢 




明天计划的事情:(一定要写非常细致的内容) 

Redis
遇到的问题:(遇到什么困难,怎么解决的) 

null
收获:(通过今天的学习,学到了什么知识)


返回列表 返回列表
评论

    分享到