今天写了半天程序,有点乏了。想想来配置一下tomcat-redis-session-manager吧,但是按照 官方文档配了总是tomcat启动错误。
1
|
java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool$Config
|
google了半天终于找到了解决办法,现记录如下。
出现上面错误的原因其实很明显,只是我太粗心了,没有找到类。
当然首先下载所需的包了:
Commons-Pool Jedis tomcat-redis-session-manager
将这些jar包都丢到tomcat的lib目录下,然后配置context.xml了,将如下内容添加到context.xml中
1
2
3
4
5
6
|
<
Valve
className
=
"com.radiadesign.catalina.session.RedisSessionHandlerValve"
/>
<
Manager
className
=
"com.radiadesign.catalina.session.RedisSessionManager"
host
=
"localhost"
<!-- optional: defaults to "localhost" -->
port="6379"
<!-- optional: defaults to "6379" -->
database="0"
<!-- optional: defaults to "0" -->
maxInactiveInterval="60"
<!-- optional: defaults to "60" (in seconds) -->
/>
|
Value字段需要出现在Manager字段之前,然后启动你的tomcat,在redis-server控制台上就可以看到如下信息了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[1638] 27 Mar 19:09:14 - Accepted 127.0.0.1:43670
[1638] 27 Mar 19:09:18 - Accepted 127.0.0.1:43671
[1638] 27 Mar 19:09:18 - 1 clients connected (0 slaves), 555984 bytes
in
use
[1638] 27 Mar 19:09:19 - Accepted 127.0.0.1:43673
[1638] 27 Mar 19:09:23 - 1 clients connected (0 slaves), 555984 bytes
in
use
[1638] 27 Mar 19:09:26 * 1 changes
in
3600 seconds. Saving...
[1638] 27 Mar 19:09:26 * Background saving started by pid 7151
[1638] 27 Mar 19:09:26 - Accepted 127.0.0.1:43683
[7151] 27 Mar 19:09:26 * DB saved on disk
[1638] 27 Mar 19:09:26 * Background saving terminated with success
[1638] 27 Mar 19:09:28 - DB 0: 1 keys (1 volatile)
in
4 slots HT.
[1638] 27 Mar 19:09:28 - 2 clients connected (0 slaves), 565608 bytes
in
use
[1638] 27 Mar 19:09:33 - DB 0: 1 keys (1 volatile)
in
4 slots HT.
[1638] 27 Mar 19:09:33 - 2 clients connected (0 slaves), 565608 bytes
in
use
[1638] 27 Mar 19:09:38 - DB 0: 1 keys (1 volatile)
in
4 slots HT.
[1638] 27 Mar 19:09:38 - 2 clients connected (0 slaves), 565608 bytes
in
use
[1638] 27 Mar 19:09:43 - DB 0: 1 keys (1 volatile)
in
4 slots HT.
|
忘了说了,tomcat-redis-session-manager不支持tomcat 7.x,tomcat 7.x的支持还在努力中啊,所以如果要用的话,请使用tomcat 6.x