我使用的是来自karelcemus版本2.0.1 https://github.com/KarelCemus/play-redis的play版本2.6.2和play-redis。根据文档,我禁用了play的默认EhCacheModule,并启用了play.api.cache.redis.RedisCacheModule并在application.conf中绑定命名缓存,下面是代码示例
play.cache.bindCaches = ["db-cache", "user-cache", "session-cache", "options-cache"]
play {
modules {
enabled += "play.api.cache.redis.RedisCacheModule"
disabled += "play.api.cache.ehcache.EhCacheModule"
}
}
play.cache.redis {
bind-default = true
instances {
play {
host: localhost
port: 6379
prefix: default
}
options-cache{
host: localhost
port: 6379
prefix: options
}
}
}对于缓存的实现,我使用play.cache.SyncCacheApi
import javax.inject.Inject;
import javax.inject.Singleton;
import play.cache.NamedCache;
import play.cache.SyncCacheApi;
@Singleton
public class GeneralOptions extends BaseOptions {
@Inject
public GeneralOptions(@NamedCache("options-cache") SyncCacheApi cache) {
super(cache);
}
}在编译时我没有在运行时得到错误下面的错误即将到来
No implementation for play.cache.SyncCacheApi annotated with @play.cache.NamedCache(value=options-cache) was bound.
while locating play.cache.SyncCacheApi annotated with @play.cache.NamedCache(value=options-cache)
for the 1st parameter of GeneralOptions.<init>(GeneralOptions.java:25)
while locating GeneralOptions所以每个类都抛出了错误,谁在使用命名缓存。你知道我缺少什么配置吗?任何建议都是值得感谢的。
发布于 2018-02-21 14:25:10
似乎作者使用了@NamedCache而不是@NamedCache,而且它既没有写在play-redis-samples中,也没有写在readme中。
https://stackoverflow.com/questions/48112233
复制相似问题