NutzCN Logo
问答 Nutz升级后,IoC注入List失败
发布于 220天前 作者 Tomcat 207 次浏览 复制 上一个帖子 下一个帖子
标签:

原可用的版本:1.r.62
升级后的版本:1.r.66
代码:

  "shiroAuthzRealms": {
    "type": "java.util.ArrayList",
    "args":[{
      "refer": "shiroAuthzRealm"
    }]
  },
  "modularRealmAuthenticator": {
    "type": "org.apache.shiro.authc.pam.ModularRealmAuthenticator",
    "fields": {
      "realms": {
        "ref": "shiroAuthzRealms"
      }
    }
  },
  "shiroSecurityManager": {
    "type": "org.apache.shiro.web.mgt.DefaultWebSecurityManager",
    "fields": {
      "authenticator": {
        "ref": "modularRealmAuthenticator"
      }
    }
  }

异常:

java.lang.RuntimeException: Fail to set '{ref=modularRealmAuthenticator}'[ {ref=modularRealmAuthenticator} ] by setter org.apache.shiro.mgt.AuthenticatingSecurityManager.'setAuthenticator()' because [org.nutz.lang.born.BorningException: Fail to born or cast to 'org.apache.shiro.authc.Authenticator'
 by args: []
 because: No suitable Constructor or Factory Method!!]: Fail to born or cast to 'org.apache.shiro.authc.Authenticator'
 by args: []
 because: No suitable Constructor or Factory Method!!
	org.nutz.lang.Lang.wrapThrow(Lang.java:170)
	org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:62)
	org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:33)
	org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	nvc.web.NutFilterDelegate.internalInit(NutFilterDelegate.java:37)
	nvc.web.NutFilterDelegate.doFilter(NutFilterDelegate.java:31)
Root Cause

org.nutz.castor.FailToCastObjectException: Fail to cast from <java.util.HashMap> to <org.apache.shiro.authc.Authenticator> for {{ref=modularRealmAuthenticator}}
	org.nutz.castor.Castors.cast(Castors.java:263)
	org.nutz.castor.Castors.castTo(Castors.java:317)
	org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:46)
	org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:33)
	org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	nvc.web.NutFilterDelegate.internalInit(NutFilterDelegate.java:37)
	nvc.web.NutFilterDelegate.doFilter(NutFilterDelegate.java:31)
Root Cause

org.nutz.lang.born.BorningException: Fail to born or cast to 'org.apache.shiro.authc.Authenticator'
 by args: []
 because: No suitable Constructor or Factory Method!!
	org.nutz.lang.Mirror.born(Mirror.java:1020)
	org.nutz.lang.Lang.map2Object(Lang.java:1175)
	org.nutz.castor.castor.Map2Object.cast(Map2Object.java:14)
	org.nutz.castor.castor.Map2Object.cast(Map2Object.java:9)
	org.nutz.castor.Castors.cast(Castors.java:253)
	org.nutz.castor.Castors.castTo(Castors.java:317)
	org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:46)
	org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:33)
	org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	nvc.web.NutFilterDelegate.internalInit(NutFilterDelegate.java:37)
	nvc.web.NutFilterDelegate.doFilter(NutFilterDelegate.java:31)
4 回复

恩,得查一下

纠正:在1.r.62里也有这个问题,似乎与在ioc里直接构建ArrayList有关?

"realms": [{
        "ref": "shiroAuthzRealm"
      }]

这样试试? 我记得是有setRealm方法的吧, 非集合的

有单个setRealm,也有List的setRealms。我是想做成可增加、替换Realm,后来改用工厂方法来构建List就没问题了。

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