NutzCN Logo
问答 关于nutzbook shiro 集成 cache 的问题
发布于 3031天前 作者 binggebest 1482 次浏览 复制 上一个帖子 下一个帖子
标签:

根据NutzBOOK 配置的cache 缓存 启动日志如下
DEBUG - Get 'cacheManager'<class net.sf.ehcache.CacheManager>
DEBUG - Ehcache CacheManager = bingge
但是登陆之后进入userprofile时报错
Fail to cast from <net.sf.ehcache.CacheManager> to <org.apache.shiro.cache.CacheManager> for {bingge}
Fail to born 'org.apache.shiro.cache.CacheManager'
Caused by: org.nutz.lang.born.BorningException: Fail to born 'org.apache.shiro.cache.CacheManager'
Caused by: java.lang.RuntimeException: Fail to set 'bingge'[ null ] to field bingge.module.BaseModule.'cacheManager' because [org.nutz.lang.born.BorningException: Fail to born 'org.apache.shiro.cache.CacheManager'

配置和nutzbook 配置一样 encache jar 为2.10 manstep 里 import net.sf.ehcache.CacheManager
和源码里一样 不太清楚是什么原因引起的

4 回复

贴完整报错信息及相关配置文件。 回复框上方有插入代码的按钮!

来自炫酷的 NutzCN

@wendal
ehcache.js
var ioc = {
cacheManager : {
type : "net.sf.ehcache.CacheManager",
factory : "net.sf.ehcache.CacheManager#getCacheManager",
args : ["bingge"] // 对应shiro.ini中指定的ehcache.xml中定义的name
}
}
dao.js
dao : {
type : "org.nutz.dao.impl.NutDao", // 1.b.53或以上版本使用原版NutDao.
args : [{refer:"dataSource"}],
fields : {
executor : {refer:"cacheExecutor"}
}
},
cacheExecutor : {
type : "org.nutz.plugins.cache.dao.CachedNutDaoExecutor",
fields : {
cacheProvider : {refer:"cacheProvider"},
// 需要缓存的表名
cachedTableNames : ["t_user_profile",
//"t_user", "t_role", "t_permission", "t_role_permission"
]
}
},
// 基于Ehcache的DaoCacheProvider
cacheProvider : {
type : "org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider",
fields : {
cacheManager : {refer:"cacheManager"} // 引用ehcache.js中定义的CacheManager
},
events : {
create : "init"
}
}
ehcache.html
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false"
monitoring="autodetect" dynamicConfig="true" name="bingge">




shiro.ini
[main]

sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
nutzdao_realm = bingge.shiro.realm.NutDaoRealm
nutzdao_realm.credentialsMatcher = $sha256Matcher

authc = org.nutz.integration.shiro.CaptchaFormAuthenticationFilter
authc.loginUrl = /user/login
logout.redirectUrl= /user/login

cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
cacheManager.cacheManagerConfigFile=classpath:ehcache.xml
nutzdao_realm.cacheManager = $cacheManager

[urls]
/rs/* = anon
/user/logout = logout
/user/error = anon
/user/profile/active/mail = anon
/user/** = authc

mainstep
CacheManager cacheManager = ioc.get(CacheManager.class);
log.debug("Ehcache CacheManager = " + cacheManager);
CachedNutDaoExecutor.DEBUG = true;

详细日志信息
2016-09-05 11:43:32,509 org.nutz.lang.inject.InjectByField.inject(InjectByField.java:29) INFO - Fail to set value by field
org.nutz.castor.FailToCastObjectException: Fail to cast from <net.sf.ehcache.CacheManager> to <org.apache.shiro.cache.CacheManager> for {bingge} because:
BorningException:Fail to born 'org.apache.shiro.cache.CacheManager'
by args: [
@(bingge)]
at org.nutz.castor.Castors.cast(Castors.java:264)
at org.nutz.castor.Castors.castTo(Castors.java:318)
at org.nutz.lang.inject.InjectByField.inject(InjectByField.java:24)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:235)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at bingge.mvc.LogTimeProcessor.process(LogTimeProcessor.java:36)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:196)
at bingge.mvc.BinggeFilter.doFilter(BinggeFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.lang.born.BorningException: Fail to born 'org.apache.shiro.cache.CacheManager'
by args: [
@(bingge)]
at org.nutz.lang.Mirror.born(Mirror.java:988)
at org.nutz.castor.castor.Object2Object.cast(Object2Object.java:12)
at org.nutz.castor.Castors.cast(Castors.java:252)
... 54 more
2016-09-05 11:43:32,512 org.nutz.ioc.impl.ScopeContext.remove(ScopeContext.java:79) DEBUG - Remove object 'userProfileModule' from [app]
2016-09-05 11:43:32,512 bingge.mvc.LogTimeProcessor.process(LogTimeProcessor.java:41) DEBUG - [ GET]URI=/212/user/profile/ 15ms
2016-09-05 11:43:32,512 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN - Error@/user/profile/ :
org.nutz.ioc.IocException: [userProfileModule] # FAIL to create Ioc Bean name=[userProfileModule]
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:235)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at bingge.mvc.LogTimeProcessor.process(LogTimeProcessor.java:36)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:196)
at bingge.mvc.BinggeFilter.doFilter(BinggeFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Fail to set 'bingge'[ null ] to field bingge.module.BaseModule.'cacheManager' because [org.nutz.lang.born.BorningException: Fail to born 'org.apache.shiro.cache.CacheManager'
by args: [
@(bingge)]]: Fail to born 'org.apache.shiro.cache.CacheManager'
by args: [
@(bingge)]
at org.nutz.lang.Lang.makeThrow(Lang.java:104)
at org.nutz.lang.inject.InjectByField.inject(InjectByField.java:30)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
... 49 more

CacheManager的package错了,是ehcache的,不是shiro的

来自炫酷的 NutzCN

@wendal
搞定了。。。谢谢

添加回复
请先登陆
回到顶部