java中关于jedis 等依赖于配置文件的类如何封装成一个通用工具类
ringa_lee
ringa_lee 2017-04-18 10:24:53
0
2
689

最近想把一些常用的工具整理成通用的工具类,比如jedis,MNS 等,但是 这些工具都依赖于配置文件:比如jedis需要配置ip,port等。如果把这些写死就失去了封装工具类的意义。
我尝试过把这些 参数写成变量,然后用构造方法初始化这些变量,得到JedisPool 等。但是这样的封装 又依赖于对象,在业务中每次都要new出来 ,无法像常用的工具类那样 变成static 方法引用。
如下图,所以想问问各位 大神有什么 好的封装思路?

ringa_lee
ringa_lee

ringa_lee

reply all(2)
左手右手慢动作

General approach:
Write the parameters that need to be configured into the configuration file (for example: redis.properties)
Load this file when the project starts, read the values ​​inside,
Initialize redisPool


The spring-data-redis spring package used in my project here is okay!

PHPzhong

These are all configurations, just write them in the configuration file. At most, different profile configurations can be switched according to the environment.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template