@@ -12,7 +12,7 @@ https://central.sonatype.com/artifact/com.litongjava/jfinal-plugins
12
12
<dependency>
13
13
<groupId>com.litongjava</groupId>
14
14
<artifactId>jfinal-plugins</artifactId>
15
- <version>1.0.6 </version>
15
+ <version>1.0.9 </version>
16
16
</dependency>
17
17
<dependency>
18
18
<groupId>redis.clients</groupId>
@@ -32,32 +32,51 @@ https://central.sonatype.com/artifact/com.litongjava/jfinal-plugins
32
32
- jedis:3.6.3 连接 reids
33
33
- fst:2.57 序列化支持
34
34
35
+ ### app.properties
36
+
37
+ ```
38
+ redis.host=127.0.0.1
39
+ redis.port=6379
40
+ redis.password=
41
+ redis.cacheName=main
42
+ ```
43
+
35
44
### RedisPluginConfig 配置类
36
45
37
46
这个类是一个配置类,用于初始化和配置 EhCache 插件。它通过 @AConfiguration 注解标记为配置类。类中的方法 redisPlugin 通过 @ABean 注解标记为 Bean 方法,框架启动时会执行该方法并将返回值放到 bean 容器中。在这个方法中,创建了一个 Plugin 实例并启动它。destroyMethod 指定在服务关闭时将会调用该方法,关闭该插件
38
47
39
48
```
40
- import com.litongjava.jfinal.aop.annotation.ABean;
49
+
41
50
import com.litongjava.jfinal.aop.annotation.AConfiguration;
51
+ import com.litongjava.jfinal.aop.annotation.AInitialization;
42
52
import com.litongjava.jfinal.plugin.redis.Cache;
43
53
import com.litongjava.jfinal.plugin.redis.Redis;
44
54
import com.litongjava.jfinal.plugin.redis.RedisPlugin;
55
+ import com.litongjava.tio.boot.server.TioBootServer;
56
+ import com.litongjava.tio.utils.environment.EnvironmentUtils;
45
57
46
58
@AConfiguration
47
59
public class RedisPluginConfig {
48
60
49
- @ABean(destroyMethod = "stop")
61
+ @AInitialization
50
62
public RedisPlugin redisPlugin() {
51
- // 用于缓存bbs模块的redis服务
52
- RedisPlugin bbsRedis = new RedisPlugin("main", "localhost");
53
- bbsRedis.start();
63
+ String host = EnvironmentUtils.getStr("redis.host");
64
+ Integer port = EnvironmentUtils.getInt("redis.port");
65
+ String password = EnvironmentUtils.getStr("redis.password");
66
+ String cacheName = EnvironmentUtils.get("redis.cacheName");
67
+
68
+ // 创建并启动 Redis 插件
69
+ RedisPlugin mainRedis = new RedisPlugin(cacheName, host, port, password);
70
+ mainRedis.start();
71
+
54
72
// 测试连接
55
73
Cache cache = Redis.use("main");
56
74
cache.getJedis().connect();
57
- return bbsRedis;
75
+
76
+ TioBootServer.me().addDestroyMethod(mainRedis::stop);
77
+ return mainRedis;
58
78
}
59
79
}
60
-
61
80
```
62
81
63
82
### 控制器
@@ -158,4 +177,4 @@ public class RedisTestController {
158
177
}
159
178
```
160
179
161
- 访问测试 http://localhost/redis/test/test01 http://localhost/redis/test/test02 http://localhost/redis/test/test03
180
+ 访问测试 http://localhost/redis/test/test01 http://localhost/redis/test/test02 http://localhost/redis/test/test03
0 commit comments